|
-
Apr 12th, 2002, 07:41 PM
#1
Thread Starter
Fanatic Member
javascript help with changing select box
I have no clue about javascripting and hope someone can.
I have a form with two select boxes as follows:
<html>
<body>
<form name="TEST1">
<p><select name="example1" size="1">
<option value="Any" selected>Any</option>
<option value="YES">Yes</option>
<option value="NO">No</option>
</select></p>
<p><select name="example2" size="1">
<option value="1" selected>choice1</option>
<option value="2">choice2</option>
<option value="3">choice3</option>
<option value="4">choice4</option>
</select></p>
</form>
</body>
</html>
Is it possible to have a javascript make a selection based on a selection of example1? If I change example1 to No I want example2 to move to choice4 and even make it so I can't change example2?
Is this possible?
Thanks.
-
Apr 12th, 2002, 08:52 PM
#2
Fanatic Member
<script>
function makeChange(){
if (frmMain.lstAnswer.options[1].selected)
frmMain.lstResult.options[2].selected = true;
}
</script>
<form NAME = "frmMain">
<select NAME = "lstAnswer" ONCHANGE = "makeChange();">
<option VALUE = "Any">Any</option>
<option VALUE = "Yes">Yes</option>
<option VALUE = "No">No</option>
</select>
<select NAME = "lstResult">
<option VALUE = "First">First</option>
<option VALUE = "Second">Second</option>
<option VALUE = "Third">Third</option>
</select>
</form>
-
Apr 13th, 2002, 07:56 AM
#3
Thread Starter
Fanatic Member
Psyrus - Thanks! That's just what I was looking for.
One more question. Is it possible to disable or freeze a combobox? Just like below when a user selects a certain item in lstAnswer it defaults lstResult. Can I get lstResult to stay that certain answer or make it like the only answer possible?
Thanks again.
-
Apr 13th, 2002, 10:02 AM
#4
Fanatic Member
<script>
function makeChange(){
if (frmMain.lstAnswer.options[1].selected){
frmMain.lstResult.options[2].selected = true;
frmMain.lstAnswer.disabled = true;
}
}
</script>
To disable it just add the code above to the script...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|