I have one problem with sending checkbox values, i have 7 checkboxes and when i send it, ajax send all 7,not just checked,here is my code:
AJAX CODE:
Code:
//Browser Support Code
function ajaxPoll(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('poll_ajax');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var a = document.getElementById('a').value;
var b = document.getElementById('b').value;
var c = document.getElementById('c').value;
var d = document.getElementById('d').value;
var e = document.getElementById('e').value;
var f = document.getElementById('f').value;
var g = document.getElementById('g').value;
var queryString = "?a=" + a + "&b=" + b + "&c=" + c + "&d=" + d + "&e=" + e + "&f=" + f + "&g=" + g;
ajaxRequest.open("GET", "/scripts/pollAjax.php" + queryString, true);
ajaxRequest.send(null);
}
HTML CODE:
Code:
<form method="POST">
<div class="sur_box"><span>1</span><spanr><input name="a" type="checkbox" class="styled" id="a" value="1" /></spanr></div>
<div class="sur_box"><span>2</span><spanr><input name="b" type="checkbox" class="styled" id="b" value="2" /></spanr></div>
<div class="sur_box"><span>3</span><spanr><input name="c" type="checkbox" class="styled" id="c" value="3" /></spanr></div>
<div class="sur_box"><span>4</span><spanr><input name="d" type="checkbox" class="styled" id="d" value="4" /></spanr></div>
<div class="sur_box"><span>5</span><spanr><input name="e" type="checkbox" class="styled" id="e" value="5" /></spanr></div>
<div class="sur_box"><span>6</span><spanr><input name="f" type="checkbox" class="styled" id="f" value="6" /></spanr></div>
<div class="sur_box"><span>7</span><spanr><input name="g" type="checkbox" class="styled" id="g" value="7" /></spanr></div>
<div id="poll_ajax">
<input name="search" type="button" onclick="ajaxPoll();" class="submit" value="SEND" id="search" />
</div>
</form>
PHP CODE:
Code:
<?php
require_once('../config.php');
if($_GET)
{
$a=$_GET["a"];
$b=$_GET["b"];
$c=$_GET["c"];
$d=$_GET["d"];
$e=$_GET["e"];
$f=$_GET["f"];
$g=$_GET["g"];
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("F j, Y, g:i a");
$tabla = mysql_query("SELECT * FROM `tb_votes` WHERE `ip`='$ip'");
$row = mysql_fetch_array($tabla);
$numrows=mysql_num_rows($tabla);
if($numrows=='0'){
$queryz = sprintf("INSERT INTO `tb_votes` (`a`,`b`,`c`,`d`,`e`,`f`,`g`,`voted_on`,`ip`) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($a),
mysql_real_escape_string($b),
mysql_real_escape_string($c),
mysql_real_escape_string($d),
mysql_real_escape_string($e),
mysql_real_escape_string($f),
mysql_real_escape_string($g),
mysql_real_escape_string($date), mysql_real_escape_string($ip));
mysql_query($queryz) or die(mysql_error());
}
}
?>
So i get added in databse all 7, but i need to add just checked ones