/    Sign up×
Community /Pin to ProfileBookmark

Requesting form variables through an ajax onclick

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);
}
[/CODE]

Link Submit–

[CODE]
echo “<a nohref=’nohref’ onClick=”ajax_request(‘index.php’, createQuery(‘create’) );”>Continue</a>”;
[/CODE]

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;
}
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @youngscotta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...