Dependent Select Form Group
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
So i'm trying to create multiple selectors in one page
but it's not really working 100%
already saw this solution [url]
when i'm trying to add more selectors boxes but not working as i expect it
Here's my code:
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
JSFiddle : [url]
Best Regards.
javascript jquery html
add a comment |
So i'm trying to create multiple selectors in one page
but it's not really working 100%
already saw this solution [url]
when i'm trying to add more selectors boxes but not working as i expect it
Here's my code:
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
JSFiddle : [url]
Best Regards.
javascript jquery html
add a comment |
So i'm trying to create multiple selectors in one page
but it's not really working 100%
already saw this solution [url]
when i'm trying to add more selectors boxes but not working as i expect it
Here's my code:
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
JSFiddle : [url]
Best Regards.
javascript jquery html
So i'm trying to create multiple selectors in one page
but it's not really working 100%
already saw this solution [url]
when i'm trying to add more selectors boxes but not working as i expect it
Here's my code:
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
JSFiddle : [url]
Best Regards.
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
var $select1 = $('#select1'),
$select2 = $('#select2'),
$select3 = $('#select3'),
$options = $select2.find('option'),
$options1 = $select3.find('option');
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');
$select2.on('change', function() {
$select3.html($options1.filter('[value="' + this.value + '"]'));
}).trigger('change');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select2" id="select2">
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 1</option>
<option value="2">Option 2</option>
</select>
<select name="select3" id="select3">
<option value="1">Option 1.1</option>
<option value="1">Option 1.2</option>
<option value="2">Option 2.1</option>
<option value="2">Option 2.2</option>
<option value="3">Option 3.1</option>
<option value="3">Option 3.2</option>
<option value="4">Option 4.1</option>
<option value="4">Option 4.2</option>
</select>
javascript jquery html
javascript jquery html
edited Jan 3 at 22:44
Khaled Mneimneh
asked Jan 3 at 22:32
Khaled MneimnehKhaled Mneimneh
114
114
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can not have equal values in the same select, each one must be unique, so I added the data-chose, which can be repeated:
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
add a comment |
Salam! tfadal ya sadee2i (here you go my friend - in Arabic :) )
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
add a comment |
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%2f54030716%2fdependent-select-form-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can not have equal values in the same select, each one must be unique, so I added the data-chose, which can be repeated:
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
add a comment |
You can not have equal values in the same select, each one must be unique, so I added the data-chose, which can be repeated:
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
add a comment |
You can not have equal values in the same select, each one must be unique, so I added the data-chose, which can be repeated:
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
You can not have equal values in the same select, each one must be unique, so I added the data-chose, which can be repeated:
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
var $select1 = $('#select1');
var $select2 = $('#select2');
var $select3 = $('#select3');
$select1.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 1:', chose);
$select2.val(chose).trigger('change');
});
$select2.on('change', function(){
var chose = $(this).find(':selected').data('chose');
console.log('chose 2:', chose);
$select3.val(chose).trigger('change');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1">
<option data-chose="1" value="1">Zahle</option>
<option data-chose="2" value="2">Other</option>
</select>
<select name="select2" id="select2">
<option data-chose="1" value="1">1 Single Phase System</option>
<option data-chose="1" value="2">2 Three Phase System</option>
<option data-chose="2" value="3">3 Single Phase System</option>
<option data-chose="2" value="4">4 Three Phase System</option>
</select>
<select name="select3" id="select3">
<option data-chose="1" value="1">1 Flat1</option>
<option data-chose="1" value="2">2 Pitched1</option>
<option data-chose="2" value="3">3 Flat2</option>
<option data-chose="2" value="4">4 Pitched2</option>
</select>
edited Jan 3 at 23:40
answered Jan 3 at 22:55
rafaelfndevrafaelfndev
464416
464416
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
add a comment |
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
Really Thank you, but i was trying to continue it but still having problems and not understanding (Sorry i'm still a newbie at js, still learning)
– Khaled Mneimneh
Jan 3 at 23:22
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
here's what i really want: link , i would appreciate it if you helped me with this :)
– Khaled Mneimneh
Jan 3 at 23:24
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
Sorry, now I add information about data-chose... I do not quite understand, do you need to remove the other options when selecting one? Or just need to select the next one according to the one selected in the first one?
– rafaelfndev
Jan 3 at 23:40
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
please check This Link to get the concept, and please if you didn't get it let me know to tell you how exactly
– Khaled Mneimneh
Jan 3 at 23:48
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
if i selected zahle show this, and if i selected other show this
– Khaled Mneimneh
Jan 3 at 23:49
add a comment |
Salam! tfadal ya sadee2i (here you go my friend - in Arabic :) )
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
add a comment |
Salam! tfadal ya sadee2i (here you go my friend - in Arabic :) )
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
add a comment |
Salam! tfadal ya sadee2i (here you go my friend - in Arabic :) )
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
Salam! tfadal ya sadee2i (here you go my friend - in Arabic :) )
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
// Dom element to store clones in it
var $clones = $('<div/>');
// Clone all select elements
$('select').each(function(){
$clones.append($(this).clone().attr('id', $(this).attr('id') + '-clone'));
});
// On a change remove the options that do not belong to the same value.
$('select[data-change]').on('change', function(){
var $this = $(this);
var selected = $this.val();
var toChange = $this.data('change').split(',');
for(id in toChange) {
var toChangeId = '#' + toChange[id];
var toChangeCloneId = toChangeId + '-clone';
$(toChangeId).html($(toChangeCloneId, $clones).html());
$(toChangeId).html($('option', toChangeId).filter('[value="' + selected + '"]'));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="select1" id="select1" data-change="select2,select3">
<option value="1">Zahle</option>
<option value="2">Other</option>
</select>
<select name="select2" id="select2">
<option value="1">Single Phase System</option>
<option value="1">Three Phase System</option>
<option value="2">Single Phase System</option>
<option value="2">Three Phase System</option>
</select>
<select name="select3" id="select3">
<option value="1">Flat1</option>
<option value="1">Pitched1</option>
<option value="2">Flat2</option>
<option value="2">Pitched2</option>
</select>
edited Jan 4 at 0:14
answered Jan 3 at 23:50
Sam BattatSam Battat
5,30511528
5,30511528
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
add a comment |
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Wsalam, shokran ktir , bas please fik ta3mel all system phases options lama 2a3mel select la we7de menon ta3tene different select 3 option.
– Khaled Mneimneh
Jan 4 at 2:51
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
Are you saying select1 will not limit options of select2, but select2 will limit options in select3? if select1 == value1 -> select2 still has value1 and value2, and if select2 == value1 -> select3 is limited to value1?
– Sam Battat
Jan 4 at 16:15
add a comment |
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%2f54030716%2fdependent-select-form-group%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