Im new to Javascript and i cannot solve this . I have a checkbox form , so i need to get the selected value(s) and post to a php file .
Here is the script :
<script>
$("#addusers").click(function(){
var checkedValue = null;
var inputElements = document.getElementsByClassName('values');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValue = inputElements[i].value;
break;
}
}
$.post("users_add.php", {
checkedValue:checkedValue
}, function(data) {
alert(data);
});
});
</script>
Here is the php code :
<td>
<div>
<?php
foreach($userProfiles as $u)
{
foreach($u as $x)
{
echo "<input type=\"checkbox\" name=\"values\"> $x";
echo "<br>";
}
}
?>
</div>
</td>
Im checking print_r($_POST) post variables , but it isnt showing anything.
Is my javascript okay ?