I have 7 checkbox, of which i want values of only selected checkbox to make further ajax query to insert data in database.
Javascript must initialize the value of selected checkbox and pass them forward to the php file were insertion is going to be made. As I am new to ajax, I am unable to understand were am I making mistake. Here is the code that I currently have.
`<script type="text/javascript">
$(document).ready(function(e) {
$("#askquestion").click(function(){
var alll = $('#alll').val();
var bff = $('#bff').val();
var relative = $('#relative').val();
var coligues = $('#coligues').val();
var acquintance = $('#acquintance').val();
var friends = $('#friends').val();
var follower = $('#follower').val();
var qid = $('#qid').val();
$.ajax({
type: "POST",
url: "ajaxaskquestion.php",
data : {
alll:alll,
bff:bff,
relative:relative,
coligues:coligues,
acquintance:acquintance,
friends:friends,
follower:follower,
qid:qid
},success: function(data){
alert("done");
},
error: function (data){
("not done");
}
});
});
});
session_start();
require_once("connect.php");
$alll = $_POST["alll"];
$bff = $_POST["bff"];
$friends = $_POST["friends"];
$coligues = $_POST["coligues"];
$relative = $_POST["relative"];
$acquintance = $_POST["acquintance"];
$follower = $_POST["follower"];
$qid=$_POST["qid"];
if(isset($_POST)){
if(isset($alll)){
// perform some function
}
else{
if(isset($bff)){
// perform some function
}
if(isset($friends)){
// perform some function
}
//and so on..
}
}
else{
echo "Question not sent";
}
I know the method which I used is very long and far away from being subtle. Any and every suggestion is welcomed. Thank you