Jim said:
I have a 2 checkboxes and a hidden field..what I want to happen is
that you can only click on 1 of these checkboxes at a time and when
you check a checkbox it will assign the hidden field "txtreferral" a
value and when you uncheck the checkbox it will set the hidden field
value back to nothing ..I have the clicking on 1 check box at a time
down but when I try to add the code to assign the value to the hidden
field I get an error in the javascript console..heres my code so far:
The two checkboxes are named txtreferral1 and txtreferral2 here is the
code for txtreferral2....
onclick="if(txtreferral1.checked)txtreferral1.che cked=!this.checked;txtreferral.value="EMPS""
1. What did the error message say?
2. Why use Javascript at all? Why not:
<input type="radio" name="txtreferral" value=""> None<br>
<input type="radio" name="txtreferral" value="OTHER"> Other<br>
<input type="radio" name="txtreferral" value="EMPS"> Emps<br>
3. Here's a very non-general solution:
Note that we don't care about the current state of the
other box or of the hidden value when a box is clicked.
<html>
<head>
<script type="text/javascript">
function boxclick(box,value){
var hidden=box.form.elements["txtreferral"];
if(box.checked){
var otherBoxName="txtreferral"+(3-box.name.charAt(box.name.length-1));
box.form.elements[otherBoxName].checked=false;
hidden.value=value;
}else{
hidden.value="";
}
}
</script>
</head>
<body>
<form>
<input type="checkbox" name="txtreferral1" onclick="boxclick(this,'OTHER')">
Other<br>
<input type="checkbox" name="txtreferral2" onclick="boxclick(this,'EMPS')">
Emps<br>
<input name="txtreferral" value="">
</form>
</body>
</html>