Download PC Drivers - Mortgages - Mortgage - Loans - Mortgage Loans

PDA

View Full Version : Checkbox


star
Mar 31st 2005, 1:06 am
Hi Experts,
I need some coding in javascript using checkbox. I got some 5 checkboxes options. There r 2 buttons users can choose more than 1 check box and clicks the button 1 and it is stored into the dbase.

Only 1 checkbox should be allowed to choose if the user chooses the button 2. If the user chooses more than 1 option an alert message should be displayed. Pls help. Anybody got any sample coding for this. Suggestions r highly appreciated. Thank You.

Regards,
Star

marty
Mar 31st 2005, 8:48 am
The are a ton of ways to do what you need. Unfortunately, without knowing what browsers and browser versions you are supporting it's impossible to give you a definitive solution, but this should get you started for on IE5+, NN6+, Mozilla, and Safari:

<input type="checkbox" name="ddd" value="" checked>
<input type="checkbox" name="ddd" value="" checked>
<input type="checkbox" name="ddd" value="">
<input type="checkbox" name="ddd" value="">
<input type="submit" name="sdfsd">
<script language="JavaScript" type="text/javascript">

//alert(document.getElementsByTagName("input").length)

var foundCount = 0
for(i=0;i<document.getElementsByTagName("input").length;i++)
{
if(document.getElementsByTagName("input")[i].type == "checkbox")
{
//alert(document.getElementsByTagName("input")[i].checked)
if(document.getElementsByTagName("input")[i].checked == true)
{
foundCount++
}
}

}

if(foundCount > 1){
alert("Emergency Will Robinson")
}

</script>

Good luck :)