Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 shaolex

shaolex
  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationLexington, KY

Posted 10 July 2006 - 03:12 PM

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!

#2 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 10 July 2006 - 03:24 PM

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.

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 10 July 2006 - 03:29 PM

Hi

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

Example:

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>

CHECKCLICK.PHP

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

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
http://thewebsolutionprovider.com - A Solution For Everything Web!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users