niurexx
asked on
submit using checkbox
i wonder if we can manipulate checkbox into submit button. what i mean i everytime user tick the checkbox, the value of checkbox will be send into database immediately. anyone can show me how to do that...?
I have the same request by in coldfusion
onclick="document.formname .submit(); return false;"
and then try
Try:
onclick="if(this.checked) this.form.submit();" ..after renaming the submit button!
and then try
Try:
onclick="if(this.checked) this.form.submit();" ..after renaming the submit button!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can someone guide me how to do that...? i need to display list of data from database and i need to create paging.. the paging is not a problem, the prob is i need to create code that use ajax to submit the data when user tick the checkbox without refreshing or changing the page..
ASKER
i've try to use onchange and it seems to be working. but i got a problem. when i tick the checkbox, it will be send on the database but the value became same with the first value of the data. can someone please check my code and make some changes. i dont know how.
form :
<script type="text/javascript">
function register(){
$.ajax({
type: "POST",
url: "submit_data.php",
data: "id=" + document.getElementById("id").value,
success: function(html){
$("#response").html(html);
}
});
}
</script>
<?
$sql = "SELECT * FROM product";
$run = mysql_query ($sql);
?><form action="" method="post"><?
while ($p = mysql_fetch_array ($run)) {
echo '<input type=checkbox id=id value='.$p[id].' onChange=register();>'.$p['product_name'].'<br>';
}
?></form>
submit_data.php :
$id = htmlspecialchars(trim($_POST['id']));
$addClient = "INSERT INTO license (title) VALUES ('$id')";
mysql_query ($addClient) or die(mysql_error());