I have the following form:
<form action="" method="get">
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/>
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/>
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/>
<input name="testbox" type="text" value="0.00"/>
<input name="testbox2" type="text" value="0.00"/>
</form>
When radio button changed, the value in the text box also changes from 0.00 to 1.00 back to 1.00 etc..
I want to do the same thing with the tick/checkbox – when clicked value in testbox2 should become 1.00, when unclicked should go back to 0.00..
The same onclick coding not working? Ideas?
Thank you
Following comments tried this.. But not working??
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function checkboxClick() {
var textbox = document.forms[0].testbox2;
textbox.value = (textbox.value == 0) ? '1.00' : '0.00';
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<form action="" method="get">
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/>
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/>
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/>
<input name="testbox" type="text" />
<input name="testbox2" type="text" value="0.00"/>
</form>
<body>
</body>
</html>
Forgot to add this change changes to onclick as suggested below.. Thank you.. Perfect..
You need to toggle the value between 0 and 1. The you’re onclick just sets the textbox to 1.00.