Jump to content

Archived

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

playaz

Disabling a text input

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
<input type="text" name="textboxname" disabled="true"/>

can just be

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

Share this post


Link to post
Share on other sites
[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"

Share this post


Link to post
Share on other sites

×

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.