Log in

View Full Version : checkbox problem



MSK7
02-17-2009, 08:31 AM
Hi to all,

actually i have a simple form called "form2" in which,
i have used some checkboxes to choose users several values of "Hobbies".

So my problem arises that,
if a person selects any one of the hobby ,
then the value of that single hobby is properly entered into the database,
But if he selects more than one hobbies then also the values of
any of them any single hobby is entered into the database,
rather than his multiple selected hobby values .

what should be done so that All the (multiple hobby) values selected by a person properly enter into the database?

its validation is shown below:-

<script type="text/javascript">

function validate_required(form2)
{
if (!form2.checkbox[0].checked && !form2.checkbox[1].checked && !form2.checkbox[2].checked )
{
alert("Please Select any Hobby");
return false;
}
return true;
}

</script>

& here its code is as follows:-

<form name="form2" onSubmit="return validate_required(this)" action="submit2.php" method="post" >


Hobbies : <input type = "checkbox" name="checkbox" id= "checkbox1" value="movies"> Movies.

<input type = "checkbox" name="checkbox" id= "checkbox2" value="reading">Reading.

<input type = "checkbox" name="checkbox" id= "checkbox3" value="sports"> Sports.


please suggest me the right code to be used or any other suggessions regarding this.

Thanks & Regards.