Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  118] [ 4]  / answers: 1 / hits: 49612  / 11 Years ago, mon, july 15, 2013, 12:00:00

This is what I have:



<script language=JavaScript>
function toggle() {
if (this.value=='1') {
document.getElementById('dbOn').style.visibility='visible';
}
else {
document.getElementById('dbOn').style.visibility='hidden';
document.getElementById('dbOff').checked='checked';
}
}
</script>

<form action=index method=post>
<input type=text name=iterations value=1 onChange=toggle() >

<input type=radio name=db value=OFF checked=checked id=dbOff >OFF<br>
<input type=radio name=db value=ON id=dbOn >ON
</form>


The idea is that you will only be allowed to write to the database if you are doing one iteration. Otherwise, I want the ON option to become disabled or disappear and for OFF to be checked automatically.



So far, I have tried onChange, onKeyUp and onKeyPress, but none of them appear to work. Any idea what is wrong with my code?



Thanks


More From » html

 Answers
31

You need to pass a reference to your element when calling the function.



onchange=toggle(this)


You'll also need a variable for the value in your function:



function toggle(element) {
if (element.value=='1') {
...

}


DEMO: http://jsfiddle.net/axxCH/1/


[#76984] Sunday, July 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
christianu questions
;