playaz Posted July 13, 2006 Share Posted July 13, 2006 I have the following script (from Glasshaus.com -their book on 'Useable forms for the web') that disables a text input depending on which radio box is selected.Is there a way to modify this, so it does the exact same thing but with a drop-down menu?Any help would be greatly appreciated :)[code]<html><head> <title>Disabling inputs</title><script language="JavaScript"> function handleOther(strRadio) { if (strRadio == "other") { document.myForm.txtOther.disabled = false; document.myForm.txtOther.value = ''; } else { document.myForm.txtOther.disabled = true; document.myForm.txtOther.value = 'not applicable'; }}</script></head><body onload="document.myForm.txtOther.disabled=true; document.myForm.txtOther.value='not applicable' ;"><h2>How did you hear about us?</h2><form name="myForm"> <input type="radio" name="radHear" value="1" onclick="handleOther(this.value);" />From a friend<br /> <input type="radio" name="radHear" value="2" onclick="handleOther(this.value);" />TV Ad<br /> <input type="radio" name="radHear" value="3" onclick="handleOther(this.value);" />Magazine Ad<br /> <input type="radio" name="radHear" value="4" onclick="handleOther(this.value);" />Newspaper Ad<br /> <input type="radio" name="radHear" value="5" onclick="handleOther(this.value);" />Internet<br /> <input type="radio" name="radHear" value="other" onclick="handleOther(this.value);" />Other... Please specify: <input type="text" name="txtOther" /></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/14462-disabling-a-text-input/ Share on other sites More sharing options...
hussain Posted July 13, 2006 Share Posted July 13, 2006 try thisfunction functionname(b){ if(b.match("playaz")) {// if matches document.form.textboxname.disabled=false; }else{ document.form.textboxname.value=""; document.form.textboxname.disabled=true; }}<form><select name="somename" onchange="return functionname(this);"><option value="playazrrrrr">value1</option><option value="value1">value1</option></select><input type="text" name="textboxname" disabled="true"/></form> Link to comment https://forums.phpfreaks.com/topic/14462-disabling-a-text-input/#findComment-57409 Share on other sites More sharing options...
True`Logic Posted July 17, 2006 Share Posted July 17, 2006 <input type="text" name="textboxname" disabled="true"/>can just be<input type="text" name="textboxname" disabled> Link to comment https://forums.phpfreaks.com/topic/14462-disabling-a-text-input/#findComment-59189 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 [quote author=True`Logic link=topic=100409.msg398438#msg398438 date=1153115376]<input type="text" name="textboxname" disabled="true"/>can just be<input type="text" name="textboxname" disabled>[/quote]Not if playaz want his/her page to be xHTML valid. It should actually be disabled="disabled" Link to comment https://forums.phpfreaks.com/topic/14462-disabling-a-text-input/#findComment-59335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.