Jump to content

javascript checkbox function insert value into database


Recommended Posts

Hi all, i would like to ask, how to insert the CHECKED check box date value into database (checked_table) and insert the UNCHECKED check box date value into database (unchecked_table)? :facepalm:

can someone please assist me on this matter? if my code is as shown below:- thank you very much.

$startDate = strtotime($datefrom);  $endDate = strtotime($dateto);  $date = $startDate;  	while( $date <= $endDate) {	echo  "<input type='checkbox' name='date' value ='".date('d-m-Y', $date)."' class='chk'>";echo date('d-m-Y', $date) .' ';  $date = strtotime('+1 day', $date); }
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script><script src="http://code.jquery.com/ui/1.9.1/jquery-ui.min.js" type="text/javascript"></script><script type="text/javascript"> $(document).ready(function () {		$("#submit_hod").click(function() {	    getValueUsingClass();	});	}); function getValueUsingClass(){		var chkArray = [];	$(".chk:checked").each(function() {		chkArray.push($(this).val());	});		var selected;	selected = chkArray.join(',') + ",";	 	if(selected.length >= 1){		alert ("done insert selected date");	}else{		alert ("error");	}}</script>
<label>Date:- FROM</label><input type="date" name="ldatefrom" value="<?php echo $leavedatefrom;?>"><label>TO</label> <input type="date" name="ldateto" value="<?php echo $leavedateto;?>"><input id="submit_hod" type="submit" name="submit">
Link to comment
Share on other sites

Give all the checkboxes a name like "date[]", which will make them an array in PHP ($_POST['date'] will be an array of checked values). Unchecked values are not submitted to the server, so you can either loop through the dates again and check if each date was submitted, or write a list of all of the checkbox values into a hidden input and submit all of the values with the rest of the form so that you can loop through them and see if each was checked or not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...