...

View Full Version : If object is 1 then object 2 is disabled? Forms



reyna12
11-07-2006, 02:25 AM
What i would like to do is this, and i am not experienced in javascript!

If aname1 = 1 then then aname2 then disabled
If aname1 = 2 then then aname2 = enabled

========

<select name="aname1" id="type">
<option selected>1</option>
<option>2</option>
</select>

========

<input type="Text" name="aname2" size="10" maxlength="9">


i had this, which didn't work ;)


if(document.forms[0].chan.value=="1")
{
document.forms[0].aname2.disabled=true
}

brandonH
11-07-2006, 03:13 AM
<form name=myform>
<select name=aname1 id=aname1 onchange="dis();">
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<input type="Text" id=aname2 name="aname2" size="10" maxlength="9" disabled=enabled>
</form>



<script type=text/javascript>
function dis(){
if (document.all || document.getElementById){
if (document.myform.aname1.value=='1')
document.myform.aname2.disabled=true
else
document.myform.aname2.disabled=false
}
}
</script>



hope this helps.....

reyna12
11-07-2006, 04:05 PM
Perfect Thanks :)

Arbitrator
11-07-2006, 04:44 PM
Heh, I see a reply now after having posted. Guess I shouldn’t have left the tab open so long. :p

<select name="aname1" id="type">Values for the name and id attributes must match.


<input … disabled=enabled>The disabled attribute does not have an “enabled” value.

Here’s the code a bit refined:

JavaScript\:
function status() {
var textField = document.getElementById("aname2");
if (document.getElementById("aname1").value == "1") textField.disabled = true;
else textField.disabled = false;
}

HTML:
<select id="aname1" onchange="status();">
<option selected>1</option>
<option>2</option>
</select>

<input type="text" id="aname2" size="10" maxlength="9" disabled>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum