I have a code in which i want to send the checked checkbpxes values to next php page with ajax call.But i am not able to send pass it properly.Previously i asked similar question some time back.
Following is the code
<html>
<head>
<title>Insert title here</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function get_check_value() {
var c_value = [];
$('input[name="services"]:checked').each(function () {
c_value.push(this.value);
});
//return c_value.join(',');
}
$(document).ready(function(){
$('#btnSubmit').on('click', function () {
alert("hi");
//var os = $('#originState').val();
//var c = $('#commodity').val();
//var ds = $('#destState').val();
var ser = get_check_value();
//var queryString = "os=" + os;
var queryString = "&ser=" + ser;
$.ajax({
type: "GET",
url:'sortingajax.php',
data:"queryString="+querystring,
success:function(data){
alert(data);
console.log(data);
$('#results').html(data);
}
});
});
});
</script>
<form name="searchForm">
<input type="checkbox" name="services" value="twic" />TWIC
<br/>
<input type="checkbox" name="services" value="enclosedTrucking" />Enclosed Trucking
<br/>
<input type="checkbox" name="services" value="flatBedTrucking" />Flat Bed Trucking
<br/>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
<div id="results">
</div>
</body>
</html>
ajaxcall.php
<?php
include('connection.php');
$query=$_GET['querystring'];
echo $query;
$countsql='SELECT * FROM table1 ';
$countsql1=mysql_query($countsql);
$numrows = mysql_num_rows($countsql1);
$countArray2=array();
while($row = mysql_fetch_array($countsql1)) {
// Append to the array
$Array2[] = $row;
}
?>
<?php
foreach($Array2 as $array)
{
?>
<div class="search">hi</div>
<?php
$i++;
}
?>
I am not able to get the content now with ajaxcall html content.but im unable to do that.. Please guide me guyzzz
If I correctly understand what you are trying to achieve, you could add hidden input to your form and pass is value, your script would set it to hidden control.
<form name="searchForm">
<input type="hidden" id="checkboxCollection">
<input type="checkbox" name="services" value="twic" />TWIC
<br/>
<input type="checkbox" name="services" value="enclosedTrucking" />Enclosed Trucking
<br/>
<input type="checkbox" name="services" value="flatBedTrucking" />Flat Bed Trucking
<br/>
<input type="submit" id="btnSubmit" value="Submit" />
</form>
then script would change to
function get_check_value() {
var c_value = [];
$('input[name="services"]:checked').each(function () {
c_value.push(this.value);
});
$('#checkboxCollection').val(c_value.join(','));
//return c_value.join(',');
}
and then read the checkboxCollection when you submit the form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.