how to setting the default value of a "checkbox" ?

liunx

Guest
I have an html form with several checkboxes.<br />
I want the data insert to my database is 1(checked) or 0(unchecked).Currently, the checkbox if checked returns 1 and this works correctly in the DB. But if the box is not checked, no value would be sent to db and just shows up blank fields in DB.<br />
<br />
Is there way to setting the defaul value to "0" unless the checkbox is checked? Here are pieces of my code:<br />
<input type="checkbox" name="C1" value="1">1. A<br />
<input type="checkbox" name="C2" value="1">2. B <br />
<input type="checkbox" name="C3" value="1">3. C<br />
<br />
Many thanks for your help! <br />
<br />
}:-)<!--content-->no, you have to do it in the serverside code you have. you have to check if it isn't checked then make it zero, if it is check then use the value.<!--content-->you can set a value by setting the checked property with script before it get submitted:<br />
<br />
if (!document.yourform.c1.checked)<br />
{<br />
document.yourform.c1.checked=true;<br />
document.yourform.c1.value="0";<br />
}<br />
<br />
will give you the desired result<!--content-->Thanks!! that really gives me some hints to work out!<!--content-->
 
Back
Top