I’ve spent over three hours on this trying to work with the code I’ve been given. I’ve never done javascript. Please help.
I have a form with 4 radio buttons, one specifying “other” and next to a text box that is supposed to post the user specified value. Here’s what I’ve tried.
HTML:
<td id="amount_container">
<input name="chargetotal" type="radio" value="75.00" onclick="donation_value();" />$75<br />
<input name="chargetotal" type="radio" value="125.00" onclick="donation_value();" />$125<br />
<input name="chargetotal" type="radio" value="250.00" onclick="donation_value();" />$250<br />
<input name="chargetotal" type="radio" value="other" />other
<input type="text" name="specified" size="10" />
</td>
javascript:
<script type="text/javascript">
function donation_value(){
var val = 0;
for( i = 0; i < document.form1.chargetotal.length; i++ ) {
if( document.form1.chargetotal[i].checked == true ) {
val = document.form1.chargetotal[i].value;
if(val=='other') {
document.form1.specified.disabled=false;
document.form1.specified.focus();
document.form1.chargetotal.value=document.form1.specified.value;
} else {
document.form1.specified.disabled=true;
}
}
}
}
</script>
It seems, you forgot to add onclick handler to “other” radio.
I think it should be
Update
I think I understood what your problem is 🙂
You can add callback, whick will be invoked when page is submitted. This callback will set value for “other” radio if it is selected. Something like
And add to form: