php - Checkbox values getting without page loading using AJAX -


i have problem getting checkbox value in following code(without page loading). if click on checkboxes values can passed through array variable check. whenever click checkbox " array ( [0] => undefined )".

here code:

index.html

<script src="create_ajax_object.js" type="text/javascript"></script> <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>  </html> 

fetchdata.php

<?php $no=array($_post['check']); foreach($no $n) {   print_r($n); }    ?> 

the variable document.myform.user array of checkbox objects, have iterate on , check checked property of each element.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -