/    Sign up×
Community /Pin to ProfileBookmark

select an item from a list box & enable same type in other list box

Hi
at first I am really sorry to put this much code. I am new to javascript. I have multiple list boxes, what I want is, when I select one or more iteams from 1st list box, all the related items in other list box should be enabled.
please help me.

[CODE]<!DOCTYPE html>
<html>
<head>
<title>Quotation</title>
<style type=”text/css”>
.auto-style1 {
text-align: center;
}
.auto-style3 {
font-size: x-large;
}
.auto-style4 {
text-align: left;
}
.auto-style5 {
font-size: x-small;
}
.auto-style6 {
font-size: small;
}
</style>
</head>
<body>
<div id=”body” class=”auto-style1″ style=”position: absolute; width: 1153px; height: 461px; z-index: 1; left: 216px; top: 19px; background-color: #F0F0F0; color: #000000; font-family: Arial, Helvetica, sans-serif”>
<label id=”Label1″><br /></label>
<br />
<strong><span class=”auto-style3″>Quotation</span></strong><div id=”cstype” class=”auto-style4″ style=”position: absolute; width: 1030px; height: 248px; z-index: 3; left: 96px; top: 117px”>
<div id=”cstypelist” class=”auto-style1″ style=”position: absolute; width: 137px; height: 230px; z-index: 1; left: 15px; top: 11px”>
<label id=”Label3″><span class=”auto-style6″><strong>Type</strong></span><br class=”auto-style5″>
</label>
<div id=”layer7″ style=”position: absolute; width: 120px; height: 204px; z-index: 1; left: 8px; top: 22px”>
<select multiple=”multiple” name=”cstype” style=”width: 106px; height: 199px”>
<option value=”cscar”>CSCar</option>
<option value=”csbus”>CSBus</option>
<option value=”cslorry”>CSLorry</option>
<option value=”csboat”>CSBoat</option>
</select>
</div>
</div>
<div id=”csdevice” class=”auto-style1″ style=”position: absolute; width: 200px; height: 230px; z-index: 1; left: 158px; top: 10px”>
<span class=”auto-style6″><strong>Devices</strong></span><label id=”Label4″><br class=”auto-style5″>
</label>
<div id=”csdevicelist” style=”position: absolute; width: 192px; height: 201px; z-index: 1; left: 8px; top: 25px”>
<select multiple=”multiple” name=”csdevice” style=”width: 191px; height: 199px”>
<option value=”cscar” disabled>CSCar Red</option>
<option value=”cscar” disabled>CSCar Blue</option>
<option value=”cscar” disabled>CSCar Green</option>
<option value=”csbus ” disabled>CSBus Red</option>
<option value=”csbus” disabled>CSBus Blue</option>
<option value=”csbus” disabled>CSBus Green</option>
<option value=”cslorry” disabled>CSLorry Red</option>
<option value=”cslorry” disabled>CSLorry Blue</option>
<option value=”cslorry” disabled>CSLorry Green</option>
<option value=”csboat” disabled>CSBoat Red</option>
<option value=”csboat” disabled>CSBoat Blue</option>
<option value=”csboat” disabled>CSBoat Green</option>
</select>
</div>
</div>
<div id=”csaccessories” class=”auto-style1″ style=”position: absolute; width: 223px; height: 230px; z-index: 1; left: 373px; top: 11px”>
<span class=”auto-style6″><strong>Accessories</strong></span><label id=”Label5″><br class=”auto-style5″>
</label>
<div id=”csaccessorieslist” style=”position: absolute; width: 207px; height: 201px; z-index: 1; left: 8px; top: 25px”>
<select multiple=”multiple” name=”csaccessories” style=”width: 196px; height: 199px”>
<option value=”cscar” disabled>CSCar Tyre</option>
<option value=”cslorry” disabled>CSLorry Tyre</option>
<option value=”cscarfix” disabled>CSCar Verification Fixture</option>
<option value=”extrabattery” disabled>Extra Battery</option>
</select>
</div>
</div>
<div id=”cssoftwarepac” class=”auto-style1″ style=”position: absolute; width: 124px; height: 230px; z-index: 1; left: 606px; top: 13px”>
<span class=”auto-style6″><strong>Software Packages</strong></span><label id=”Label6″><br class=”auto-style5″>
</label>
<div id=”cssoftwarepaclist” style=”position: absolute; width: 110px; height: 201px; z-index: 1; left: 8px; top: 25px”>
<select multiple=”multiple” name=”softwarepackage” style=”width: 104px; height: 199px”>
<option>Audit Lite</option>
<option>Audit</option>
<option>Audit Plus Pro</option>
<option>PLS</option>
</select>
</div>
</div>
<div id=”csmaintenancehardware” class=”auto-style1″ style=”position: absolute; width: 234px; height: 230px; z-index: 1; left: 748px; top: 13px”>
<span class=”auto-style6″><strong>Maintenance Plans (Hardware)</strong></span>
<div id=”csmaintenancehardwarelist” style=”position: absolute; width: 220px; height: 201px; z-index: 1; left: 6px; top: 25px; right: 8px;”>
<strong>
<select multiple=”multiple” name=”csmaintenancehardware” style=”width: 214px; height: 199px”>
<option value=”cscar” disabled>CSCar Standard Kit</option>
<option value=”cscar” disabled>CSCar Bluetooth Kit</option>
<option value=”cscar” disabled>CSCar Wi-Fi Kit</option>
<option value=”cslorry” disabled>CSLorry Standard Kit</option>
<option value=”cslorry” disabled>CSLorry Bluetooth Kit</option>
<option value=”cslorry” disabled>CSLorry Wi-Fi Kit</option>
<option value=”csboat” disabled>CSBoat Standard Kit</option>
<option value=”csboat” disabled>CSBoat Bluetooth Kit</option>
<option value=”csboat” disabled>CSBoat Wi-Fi Kit</option>
<option value=”expire” >Expired Year Maintenance Plan</option>
</select>
</strong>
</div>
</div>
</div>
</div>
</body>
</html>
[/CODE]

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@rootDec 05.2016 — [Removed] posted in wrong web site Ooops!
Copy linkTweet thisAlerts:
@rootDec 05.2016 — I suggest that you opt for populating the selects with the desired elements rather than deleting or enabling them.
Copy linkTweet thisAlerts:
@shumoniraauthorDec 05.2016 — are you talking about my post?
Copy linkTweet thisAlerts:
@shumoniraauthorDec 05.2016 — I just need to enable them when I select from 1st list box
Copy linkTweet thisAlerts:
@rootDec 05.2016 — The general accepted mode is to populate a select with the desired elements.
Copy linkTweet thisAlerts:
@SempervivumDec 05.2016 — You have five select-options. Which should be the master? Should the selection in the master affect all other selects? Do you want to disable the non-active options only or do you want to make them invisible?
Copy linkTweet thisAlerts:
@shumoniraauthorDec 05.2016 — You have five select-options. Which should be the master? Should the selection in the master affect all other selects? Do you want to disable the non-active options only or do you want to make them invisible?[/QUOTE]

the 1st one from the left side it the master. I already disabled them & keep few of them enabled because they will be always enable. so when I select CSCar, then all other car related iteams from the other list box should be enabled.
Copy linkTweet thisAlerts:
@SempervivumDec 05.2016 — You did not yet answer these questions:Should the selection in the master affect all other selects? Do you want to disable the non-active options only or do you want to make them invisible?[/QUOTE]
Copy linkTweet thisAlerts:
@shumoniraauthorDec 05.2016 — You did not yet answer these questions:[/QUOTE]

yes, it should affect all other related selects, and all other non-active option should be there.
Copy linkTweet thisAlerts:
@SempervivumDec 05.2016 — This should do the job:[CODE] var configopts = {
"cscar": {
"csdevice": [false, true, true, true, true, true, true, true, true, true, true, true],
"csaccessories": [true, false, true, true],
"softwarepackage": [true, true, false, true],
"csmaintenancehardware": [true, true, true, false, true, true, true, true, true, true]
},
"csbus": {
"csdevice": [true, true, true, false, true, true, true, true, true, true, true, true],
"csaccessories": [true, true, false, true],
"softwarepackage": [true, false, true, true],
"csmaintenancehardware": [false, true, true, true, true, true, true, true, true, true]
},
"clorry": {
"csdevice": [true, true, true, true, true, true, true, true, true, true, true, true],
"csaccessories": [true, true, true, true],
"softwarepackage": [true, true, true, true],
"csmaintenancehardware": [true, true, true, true, true, true, true, true, true, true]
},
"cboat": {
"csdevice": [true, true, true, true, true, true, true, true, true, true, true, true],
"csaccessories": [true, true, true, true],
"softwarepackage": [true, true, true, true],
"csmaintenancehardware": [true, true, true, true, true, true, true, true, true, true]
}
};
$("select[name='cstype']").on("change", function () {
var type = $("select[name='cstype'] > option:selected").val();
for (selname in configopts[type]) {
var currarr = configopts[type][selname];
$("select[name='" + selname + "'] > option").each(function (idx) {
$(this).prop("disabled", !currarr[idx])
});
}
});[/CODE]
You need to adjust the array in order to enable (true) the proper options.
Copy linkTweet thisAlerts:
@SempervivumDec 05.2016 — PS: And you need to include jQuery:[CODE] <script src="//code.jquery.com/jquery-1.10.2.js"></script>[/CODE]
×

Success!

Help @shumonira spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...