views:

51

answers:

1

Hi, Im trying to create a page that allows a user to select a maximum of 8 checkboxes out of 25 checkboxes total, While at the same time detecting the exact order the user clicked the checkboxes.

My question is, What code can I add to the javascript to gather this info and pass it along to a page named check_combination.php I have been told that this would be a hidden field, But being a noob Im stuck. Can someone please tell me what code i would need to gather it, and what type of code I would nee to extract it on check_combination.php

Here is an exaple of what I have so far Click Here to test in Real Time at JSFIDDLE

I am a noob to javascript, but I have been able to piece together various snippets of code to get as far as I have. The only thing I am missing is Im not sure how to pass the variables along when a user hits the submit button.

A: 

You're already there. After you submit the form the result values will be submitted as well, and you can find them in $_POST['result'] using PHP.

Alec
Gotcha, so since the name of the textarea is "result", I can just use the post on the php page? Ive tried $result = $_POST["result"]; echo "$result"; Not getting any output, is this close to what I need on the check_combination.php page?
James
That should show the results. Try `<?php echo '<pre>'; print_r($_POST); echo '</pre>'; ?>`; this should show everything that was posted with the form. Also, people can now still edit the results, so make sure to hide the textarea using CSS or change it into a `<input type="hidden" />` element.
Alec
I used the code above, the only output I am getting is the last checkbox checked. Here is the output (I check 2 other boxes) Array( [checkbox] => 3 [button] => Submit)it doesnt seem as though the textarea is getting submitted
James
Disregard, There is a small difference between what im using and what I added to jsfiddle, Just tried it on my code from js fiddle, and I seem to be gettin the output. Thank you for helping me :)
James
One last thing. any idea how to change the text area from visible to hidden?
James
What I mean is, how to make the textarea hidden in javascript once I make the text area hidden in the form, it doesnt post the results
James
Everything gets posted, as long as it exists between the `<form>` and `</form>` tags. You can hide the textarea by adding e.g. `style="display:none;"` or add a class that has similar CSS. But it doesn't have to be a textarea; you can use `<input type="hidden" name="result" id="result" />`.
Alec