|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm using this code to enable the sumbit button.
The problem is that it enables on odd numbers of ticks once even it disables thee button. Basically it disables the checkbox until one checkbox is ticked. Code:
<input type="checkbox" onClick="document.all['mysubmit'].disabled =(document.all['mysubmit'].disabled)? false : true"> <input type="submit" id="mysubmit" value="submit" disabled> I just want it to enable if 1 or all checkboxes are ticked. Can anyone help me out. Thank you
__________________
Life is Good |
|
#2
|
||||
|
||||
|
This should work for you:
Code:
<form name="form1" id="form1">
<input type="checkbox" name="checkbox" id="chk" onChange="chkCount();" /><br />
<input type="checkbox" name="checkbox" id="chk" onChange="chkCount();" /><br />
<input type="checkbox" name="checkbox" id="chk" onChange="chkCount();" /><br />
<input type="submit" name="submit" id="submit" disabled="disabled" />
</form>
<script language="javascript" type="text/javascript">
function chkCount()
{
// assign a 0 value to the number of selected checkboxes variable
var chkTotal = 0;
// loop though the checkboxes and count how many are checked
for(counter=0;counter<document.form1.checkbox.length;counter++)
{
if(document.form1.checkbox[counter].checked)
{
chkTotal = chkTotal + 1;
}
}
// if at least 1 checkbox is checked, activate the submit button
if (chkTotal > 0)
{
document.form1.submit.disabled=false;
}
else
// leave the submit button disabled
{
document.form1.submit.disabled=true;
}
}
</script>
__________________
-
thought-after | my thoughts on web development Get Firefox, the developers browser Budget hosting - recommended [/left] |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Enable submit button problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|