Jump to content

How can I record the order of clicked checkboxes in PHP/MySQL?


shaolex

Recommended Posts

I have written a form for entering publications for a webpage.  At the bottom of the form, there are a series of checkboxes which allow the user to select the author(s) from a list of faculty members.  However, when the data is written into the database, the order of the authors corresponds to their keys in from the table of authors, not the order clicked on the webpage.  This is a problem because the primary author/researcher is not being listed first.  Is there anyway to preserve the clicking order when the form passes it as an array to the PHP script?

Does any of this make sense?

Thanks in advance to anyone who can offer some help and/or suggestions!
Link to comment
Share on other sites

Ooh a brainteaser. Sounds like a dynamic on static problem. I'd suggest using event handling in Javascript to create your sequence of numbers. They would be dynamically created on the static page when a user checks the box and placed in a hidden or disabled field on the form. Then when the form is submitted, the clicking order is preserved.
Link to comment
Share on other sites

Hi

You could try an onClick event to trap the checkbox that is clicked.

Example:

[code]
EXAMPLE.PHP

<form name="form1" action="action.php" method="post">
  <input type="checkbox" name="C1" value="Author1" onClick="location.href='checkclick.php?box=C1">
  <input type="checkbox" name="C2" value="Author2" onClick="location.href='checkclick.php?box=C2'">
</form>
[/code]

[code]
CHECKCLICK.PHP

$clicked_box = $_GET['box'];
$box_order_array[number] = $clicked_box
header ("Location: example.php?box=$clicked_box");
[/code]

Obviously you will need code in the EXAMPLE.PHP to trap the return and put a check in the corresponding box. And you will probably need a global variable (to count the number of boxes clicked for the array in CHECKCLICK.PHP), unless you just use the same page (ie action="<? $_SERVER['PHP_SELF']; ?>")

Or you could use JavaScript!

Hope this kinda sheds some light
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.