Jump to content

Disable textbox based on dropdown selection


refiking

Recommended Posts

Here's what I have.  I can't get it to work for anything in the world...

 

Static or Random?
<select name="staticrand" id"staticrand" onchange="enableTextbox()">
<option value="static">Static</option>
<option value="rand" selected="selected">Random</option>
</select>

Static ID
<input type="text" value="0" name="staticid" id="staticid" maxlength="3" disabled="true" />

<script type = "text/javascript">
function enableTextbox() {
var val = document.getElementById("staticrand").selectedIndex;
if (val == 'static') { document.getElementById("staticid").disabled = false}
else { document.getElementById("staticid").disabled = true}
}
</script>

okay number 1 error that i see, if you copied pasted this code, is that you are missing an equal sign in your id, this line

<select name="staticrand" id"staticrand" onchange="enableTextbox()">

needs to be

<select name="staticrand" id="staticrand" onchange="enableTextbox()">

in order for any part of your code to work, also, you need to add a couple of lines to correctly execute your code. try

Static or Random?
<select name="staticrand" id="staticrand" onchange="enableTextbox()">
<option value="static">Static</option>
<option value="rand" selected="selected">Random</option>
</select>

Static ID
<input type="text" value="0" name="staticid" id="staticid" maxlength="3" disabled="true" />

<script type = "text/javascript">
function enableTextbox() {
var val = document.getElementById("staticrand").selectedIndex;
var op = document.getElementById("staticrand").options;
if (op[val].text == 'static') { document.getElementById("staticid").disabled = false}
else { document.getElementById("staticid").disabled = true}
}
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.