Jump to content


Photo

Disabling a text input


  • Please log in to reply
3 replies to this topic

#1 playaz

playaz
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 13 July 2006 - 10:02 AM

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 :)

<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>


#2 hussain

hussain
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 13 July 2006 - 04:19 PM

try this

function 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>

#3 True`Logic

True`Logic
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 17 July 2006 - 05:49 AM

<input type="text" name="textboxname" disabled="true"/>

can just be

<input type="text" name="textboxname" disabled>

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 01:39 PM

<input type="text" name="textboxname" disabled="true"/>

can just be

<input type="text" name="textboxname" disabled>

Not if playaz want his/her page to be xHTML valid. It should actually be disabled="disabled"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users