Jump to content

Disabling a text input


playaz

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]
Link to comment
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>
Link to comment
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"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.