I’m currently working on a form submit using an onClick ajax request instead of a submit input. When the onClick is toggled and the page requests the checkbox array it’s grabbing the values of the checkbox array and outputting them as the array values.
What I need from the code is for the checkbox values to be set as the array keys, and know whether or not the specific array key is checked (0 for null, 1 for checked). If it’s working properly, after submitting the form through the onClick it should display which checkboxes are checked after reloading the page.
Other information is being passed through the form as well, and there is a need for the values of each input. Is it possible to add onto the createQuery function to check to see if it’s a checkbox and pass the information correctly, while still using it to grab the values of the other inputs?
Source–
[CODE]
$_id = $_REQUEST[‘id’];
$var = $_REQUEST[‘obj’];
$list = $mysql->query( ‘select * from list where id = ” ‘.$_id.’ “‘ );
while( $row = $mysql->fetch( $list ) )
{
if( $var ){
if( if( $var[$row[‘id’]] == 1 )
$add = ‘checked=”yes”‘;
}
echo $row[‘name’].’: <input type=”checkbox” ‘.$add.’ id=”obj[]” name=”obj[]” value=”‘.$row[‘id’].'”> ‘;
unset($add);
}
Link Submit–
[CODE]
echo “<a nohref=’nohref’ onClick=”ajax_request(‘index.php’, createQuery(‘create’) );”>Continue</a>”;
createQuery–
[CODE]
function createQuery(form)
{
var elements = document.getElementById(form).elements;
var pairs = new Array();
for (var i = 0; i < elements.length; i++) {
if ((name = elements[i].name) && (value = elements[i].value))
pairs.push(name + “=” + encodeURIComponent(value));
}
var toreturn = pairs.join(“&”);
return toreturn;
}