Click here to Skip to main content
16,017,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello I have problem in reading and sending checkbox value I tried using ajax but it didn't work
HTML
function defaultt(id) {
        $.ajax({

            type : "POST",
            data : "id=" + id,
            url : "defaultt.php",
            success : function(msg) {
                $('#' + id).fadeOut(300);
            }
        });

code:
HTML
<td><form><input type="checkbox" name="state" id="state"class="check"  checked onClick='javascript:defaultt(" . $row['ID'] . ");' >

retrieve code in other page.php:
PHP
<?php $state=$_POST['id']
      //here insert to db statment
?>

I used (vishnu Prajapati) code:
first of all thank you very much for your time. I used your code but the ajax didn work with me
nothing happend
I want a way to submit without the input of type submit? why the ajax didn't work?
Posted
Updated 12-Oct-13 4:35am
v5
Comments
Vishnu Prajapati 14-Oct-13 0:11am    
please try using (document).ready{ ajax code here }
Vishnu Prajapati 14-Oct-13 0:14am    
ya you are absolutelely using css can submit without type submit i.e. vote 3 down vote


You can add style with CSS even if there is no class/id. The following selects all input elements with attribute type="submit":

input[type="submit"]{
/* style */
}

The above is very generic, it's better to be more exclusiver. So include some of its parents , preferable those with an ID/class:

div#someID form input[type="submit"]{
/* style */
}

(assuming a parent <div id="someID">)
share|improve this answer

1 solution

XML
<script language="javascript" type="text/javascript">
function display()
{
    var ajax = create_ajax_object();
    if (ajax)
    {
        ajax.onreadystatechange = function ()
        {
            if (ajax.readyState == 4 && ajax.status == 200)
            {
                document.getElementById("target").innerHTML = ajax.responseText;
            }
        }
        ajax.open("POST", "fetchdata.php", true);
        var check = new Array();
        var "check[]=" + encodeURIComponent(document.myForm.user.value);
        ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajax.send(check[]);
    }
    else
    {
        alert("Your browser doesnt support AJAX!");
    }
}
</script>
<br>
<form name='myForm'>
    <input type="checkbox" name="user" value="First" onclick="display();">1
    <br>
    <input type="checkbox" name="user" value="Second" onclick="display();">2
    <br>
    <input type="checkbox" name="user" value="Third" onclick="display();">3
    <br>
</form>
 
Share this answer
 
v2
Comments
Rawan S 12-Oct-13 9:59am    
thank you very much but the ajax didn't work with me like the last method
Vishnu Prajapati 14-Oct-13 0:10am    
please try using (document).ready{ ajax code here }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900