Click to See Complete Forum and Search --> : Checkbox
florida
05-22-2003, 07:15 AM
For a checkbox how can I make it check automatically when I exit the form?
function checkButton
{
var e1;
if (!e1.checked)
{
return true;
//how do I put a check in the check box here?
}
}
<input type="checkbox" name="fieldhere">
wildwobby
05-22-2003, 07:17 AM
<input type="checkbox" value="true" name="fieldhere">
florida
05-22-2003, 07:25 AM
Thanks for the quick response. Dont I need to call the function somewhere?
wildwobby
05-22-2003, 07:28 AM
the way i told u was the way i learned
Try something like this:
<script language="JavaScript" type="text/JavaScript">
function checkButton(frm) {
if (!frm.fieldhere.checked) {
frm.fieldhere.checked = true;
}
}
</script>
</head>
<body>
<form name="myform" onsubmit="checkButton(this);">
<input type="checkbox" name="fieldhere" />
<input type="submit" value="Submit" />
</form>
Pyro, you left out the "return true" part. If you don't have that in there, it won't actually check the box:
<script type="text/JavaScript">
function checkButton(frm) {
if (!frm.fieldhere.checked) {
frm.fieldhere.checked = true;
return true;
}
}
</script>
</head>
<body>
<form name="myform" onsubmit="checkButton(this);">
<div>
<input type="checkbox" name="fieldhere">
<input type="submit" value="Submit">
</div>
</form>
No, it won't. :p Test your code in IE6.
http://www.infinitypages.com/temp/testform2.htm Don't check the box, and hit submit...
Hmmm.... Strange, but that never worked for me before. I always had to use return true; to get it to work.. Otherwise it wouldn't. I wonder why... Maybe some kind of bug in my computer...
florida
05-22-2003, 11:08 AM
Thanks that works great with onsubmit but I think I need to get it to work with body onload.
I tried this:
<body onunload="review.checked=true">
and it did not work.
I want this box to get checked when someone closes/exits the page or goes to another page.
onUnLoad="document.myform.fieldname.checked=true;"
florida
05-22-2003, 12:26 PM
Thanks again to both of you for solving my problem.