Forum Moderators: open

Message Too Old, No Replies

Button event based on checkbox selection

         

jay422

8:12 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Hi,

I'm trying to create a form button that when clicked on has to show a new form layer based on the selection of one (out of three) checkboxes selected.

I wrote this code. Let me know how I can fix it.

<head>
<script language="JavaScript">
function N2.click() {
If (document.Mother's Day Donation.Card == "Yes")
{showLayer('page3')}

else

{showLayer('page4')}
}
</script>
</head>

<body>
<form name="Mother's Day Donation">
<input type="checkbox" name="Card" value="Yes" border="0">Mail
<input type="checkbox" name="Card" value="E-card" border="0">E-card
<input type="checkbox" name="Card" value="No" border="0">NO card

<input type=button id=N2 value="NEXT >>" onClick="javascript:N2.click()">

</form>
</body>

The showLayer(lyr) function is setup and functioning in other sections of the form.

Any input will be truly appreciated! Thanks.

rocknbil

3:22 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got it to work like this. One, no spaces in object names, it will submit server-side that way but Javascript doesn't like it. Two, you name radio buttons all the same but not checkboxes, their names must be unique.
I'm not sure about dot syntax in function names, couldn't get it to work until I removed the dots.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<script language="JavaScript">
function N2click() {
if (document.mdd.Card.checked == true) { showLayer('page3'); }
else { showLayer('page4'); }
}
function showLayer (layerName) { alert(layerName); }
</script>
</head>

<body>
<form name="mdd">
<input type="checkbox" name="Card" value="Yes" border="0">Mail
<input type="checkbox" name="eCard" value="E-card" border="0">E-card
<input type="checkbox" name="noCard" value="No" border="0">NO card

<input type=button id="N2" value="NEXT >>" onClick="N2click()">

</form>
</body>
</html>

Another problem I see is that if you have form elements in other divs (layers) you'll have to do some Javascript to gather them all into one submit, I've had no success in finding a way to show/hide layers in a single form. That is, you can do
<div><form></form></div> <div><form></form></div>
but not
<form><div></div> <div></div></form>

And have the dynamic show/hides work out.

Someone please prove me wrong, I've always worked around this one . . .