refiking Posted June 11, 2011 Share Posted June 11, 2011 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> Link to comment https://forums.phpfreaks.com/topic/239028-disable-textbox-based-on-dropdown-selection/ Share on other sites More sharing options...
fugix Posted June 11, 2011 Share Posted June 11, 2011 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> Link to comment https://forums.phpfreaks.com/topic/239028-disable-textbox-based-on-dropdown-selection/#findComment-1228198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.