php - Sending input array via AJAX -


i've dealt javascript in past, i'm trying relearn it. reason i'd come javascript solution without use of libraries jquery.

i've come across several threads, , have been close not perfect match situation.

i have form generated dynamically php, grabs info database, , echoes out form inputs. checkboxes representing entry in database. use name="id[value]" value id of current entry being looped through.

so have this:

<input type="checkbox" name="del[1]"/> <input type="checkbox" name="del[2]"/> <input type="checkbox" name="del[3]"/> 

when post on form submit, value of $_post['del'] , call day. however, i'm trying send php page ajax function can perform functions without changing page or refreshing.

my question is: how of checkboxes(that checked) , send them php page can understand ones checked. understanding require kind of conversion. first though loop through each checked box, , grab index (or give them ids , grab id) , put string explode php side.

any thoughts? thanks, sharf.

var i, child, str='', arr = array(),     form = document.getelementbyid('form')  for(i=0; i<form.childnodes.length; i++) {     // grab element     var child = form.childnodes[i];     // make sure input , checkbox     if(child.tagname!='input' || child.getattribute('type')!='checkbox') continue     // if checkbox checked, add name , value url string     if(child.checked)         arr.push(child.getattribute('name')+'='+encodeuricomponent(child.value))     } }  // make url string str = arr.join('&')  // can use url:  someajaxurl + str 

then, in php:

<?php     $checked_options = $_request['del'];     print_r($checked_options); ?> 

Comments