Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enabling radio after typing specific query 1

Status
Not open for further replies.

LuckySyringe

Technical User
Oct 11, 2005
35
US
I might be going about this all wrong, but I'm attempting a script that will enable a radio button once a specific query is typed into a text input box. I've added a small (non-working) sample, and as you can probably tell, javascript isn't my strong point...

Code:
<script type="text/javascript">
function checkText() {
var code = document.getElementById("txtCode")
var special = document.getElementById("radSpecial")
     if (code = "special code")
     {
          special.disabled = false;
     }else{
          special.disabled = true;
     }
}
</script>

<form name="test_form">
<input type="text" id="txtCode" onkeyup="checkText()" /><br />
<input type="radio" id="radSpecial" name="radios" value="special" disabled="disabled" />&nbsp;A&nbsp;|&nbsp;
<input type="radio" name="radios" value="normal_1" />&nbsp;B<br />
<input type="radio" name="radios" value="normal_2" />&nbsp;C&nbsp;|&nbsp;
<input type="radio" name="radios" value="normal_3" />&nbsp;D
</form>

... If it were earlier on in the day I would probably have been able to write a better script, my logic gets worse as the day progresses.
 
There are just a couple things you missed:
Code:
<script type="text/javascript">
function checkText() {
var code = document.getElementById("txtCode")[COLOR=red].value[/color]
var special = document.getElementById("radSpecial")
     if (code =[COLOR=red]=[/color] "special code")
     {
          special.disabled = false;
     }else{
          special.disabled = true;
     }
}
</script>
The first change is to get the value of the textbox into the variable. The second change has to be "==" because if it is one equal sign, it assigns the value on the left to whatever is on the right. The equality operator uses two equal signs.

Hope that helps.

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top