Laravel Hide selected value in multiple dropdown list
I have supplier table and retrieving all the data then pass it in my view. One of my module I have 3 dropdown list of all supplier.
I want to hide the selected value in other dropdown list
Example:
1) First dropdown
> supplier 1
> supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
When I select the supplier 1 in first dropdown, it wont show on the remaining dropdown.
View
@extends('layouts.app')
@section('content')
<?php $counter=3;?>
@for($x = 1; $x<=$counter;$x++)
<select id="supplier{{$x}}">
@foreach($data as $row)
<option value="{{$row->supplier_name}}">{{$row->supplier_name}}</option>
@endforeach
</select>
@endfor
<script type="text/javascript">
var $supplier1 = $("select[id='supplier1']");
var $supplier2 = $("select[id='supplier2']");
var $supplier3 = $("select[id='supplier3']");
$supplier1.change(function() {
$supplier2.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier2.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier3.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier2.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
</script>
@endsection
Question: How can I hide the selected value in my dropdown list?
Updated:
I updated my code, it can be now disabled when it is already selected but there's a problem. If I chose any dropdown
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
In 2nd & 3rd dropdown you cant now choose supplier 2 but when I Selected another value in 2nd or 3rd dropdown it can now select the Supplier 2.
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> Selected supplier 3
3) Third dropdown
> supplier 1
> supplier 2(Can now select)
> supplier 3
Question: How can I disabled the 1st & 2nd selected value in dropdown?
javascript jquery laravel-5.7
add a comment |
I have supplier table and retrieving all the data then pass it in my view. One of my module I have 3 dropdown list of all supplier.
I want to hide the selected value in other dropdown list
Example:
1) First dropdown
> supplier 1
> supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
When I select the supplier 1 in first dropdown, it wont show on the remaining dropdown.
View
@extends('layouts.app')
@section('content')
<?php $counter=3;?>
@for($x = 1; $x<=$counter;$x++)
<select id="supplier{{$x}}">
@foreach($data as $row)
<option value="{{$row->supplier_name}}">{{$row->supplier_name}}</option>
@endforeach
</select>
@endfor
<script type="text/javascript">
var $supplier1 = $("select[id='supplier1']");
var $supplier2 = $("select[id='supplier2']");
var $supplier3 = $("select[id='supplier3']");
$supplier1.change(function() {
$supplier2.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier2.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier3.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier2.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
</script>
@endsection
Question: How can I hide the selected value in my dropdown list?
Updated:
I updated my code, it can be now disabled when it is already selected but there's a problem. If I chose any dropdown
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
In 2nd & 3rd dropdown you cant now choose supplier 2 but when I Selected another value in 2nd or 3rd dropdown it can now select the Supplier 2.
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> Selected supplier 3
3) Third dropdown
> supplier 1
> supplier 2(Can now select)
> supplier 3
Question: How can I disabled the 1st & 2nd selected value in dropdown?
javascript jquery laravel-5.7
add a comment |
I have supplier table and retrieving all the data then pass it in my view. One of my module I have 3 dropdown list of all supplier.
I want to hide the selected value in other dropdown list
Example:
1) First dropdown
> supplier 1
> supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
When I select the supplier 1 in first dropdown, it wont show on the remaining dropdown.
View
@extends('layouts.app')
@section('content')
<?php $counter=3;?>
@for($x = 1; $x<=$counter;$x++)
<select id="supplier{{$x}}">
@foreach($data as $row)
<option value="{{$row->supplier_name}}">{{$row->supplier_name}}</option>
@endforeach
</select>
@endfor
<script type="text/javascript">
var $supplier1 = $("select[id='supplier1']");
var $supplier2 = $("select[id='supplier2']");
var $supplier3 = $("select[id='supplier3']");
$supplier1.change(function() {
$supplier2.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier2.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier3.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier2.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
</script>
@endsection
Question: How can I hide the selected value in my dropdown list?
Updated:
I updated my code, it can be now disabled when it is already selected but there's a problem. If I chose any dropdown
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
In 2nd & 3rd dropdown you cant now choose supplier 2 but when I Selected another value in 2nd or 3rd dropdown it can now select the Supplier 2.
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> Selected supplier 3
3) Third dropdown
> supplier 1
> supplier 2(Can now select)
> supplier 3
Question: How can I disabled the 1st & 2nd selected value in dropdown?
javascript jquery laravel-5.7
I have supplier table and retrieving all the data then pass it in my view. One of my module I have 3 dropdown list of all supplier.
I want to hide the selected value in other dropdown list
Example:
1) First dropdown
> supplier 1
> supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
When I select the supplier 1 in first dropdown, it wont show on the remaining dropdown.
View
@extends('layouts.app')
@section('content')
<?php $counter=3;?>
@for($x = 1; $x<=$counter;$x++)
<select id="supplier{{$x}}">
@foreach($data as $row)
<option value="{{$row->supplier_name}}">{{$row->supplier_name}}</option>
@endforeach
</select>
@endfor
<script type="text/javascript">
var $supplier1 = $("select[id='supplier1']");
var $supplier2 = $("select[id='supplier2']");
var $supplier3 = $("select[id='supplier3']");
$supplier1.change(function() {
$supplier2.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier2.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier3.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier3.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
$supplier3.change(function() {
$supplier1.find('option').prop("disabled", false);
$supplier2.find('option').prop("disabled", false);
var selectedItem = $(this).val();
if (selectedItem) {
$supplier1.find('option[value="' + selectedItem + '"]').prop("disabled", true);
$supplier2.find('option[value="' + selectedItem + '"]').prop("disabled", true);
}
});
</script>
@endsection
Question: How can I hide the selected value in my dropdown list?
Updated:
I updated my code, it can be now disabled when it is already selected but there's a problem. If I chose any dropdown
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> supplier 3
3) Third dropdown
> supplier 1
> supplier 2
> supplier 3
In 2nd & 3rd dropdown you cant now choose supplier 2 but when I Selected another value in 2nd or 3rd dropdown it can now select the Supplier 2.
Scenario:
1) First dropdown
> supplier 1
> Selected supplier 2
> supplier 3
2) Second dropdown
> supplier 1
> supplier 2
> Selected supplier 3
3) Third dropdown
> supplier 1
> supplier 2(Can now select)
> supplier 3
Question: How can I disabled the 1st & 2nd selected value in dropdown?
javascript jquery laravel-5.7
javascript jquery laravel-5.7
edited Jan 20 at 2:31
Angel
asked Jan 19 at 16:14
AngelAngel
293524
293524
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268991%2flaravel-hide-selected-value-in-multiple-dropdown-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268991%2flaravel-hide-selected-value-in-multiple-dropdown-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown