Re: Validating Radio Buttons in two directions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HiFi:

 Thanks so much Tedd for the JavaScript.  I will keep that snippet for use
and study to improve my JS skills.

Unfortunately I should have said that I need to stay away from JS in case
the users have shut that down in their browsers.  I know I can detect that
and have them turn it on but I'm dealing with folks who are not technically
adept and the survey is long.  Given the length of the survey (over 100
questions) any additional hurdles will further lower the rate of return.  So
I  really think I need to do this in PHP though I am open to suggestions
here.

Okay, no js.

So, let's look at the problem. You have ten rows and ten columns -- that's 100 choices that can be recorded by a simple ten element array(10).

For example, all radio button groups have ten possibilities. Let's say radio group-one has radio button three marked -- so, your array would be:

array(1)=3 (means row one has button 3 selected)

The second row has button 9 checked, the array would be:

array(2)=9 (means row two has button 9 selected)

And so on.

The array has to be filled from the radio buttons. You do that from taking the values from each group and filling the array accordingly after the user submits the form. Be careful not to duplicate the names of the buttons.

After the user clicks "Submit", you'll need to travel through the array checking each indexed value for duplication.

To do this, start at the first index and if its value is greater than zero, then compare its value to all other values. If you find a duplication, then zero the offending value and repeat as necessary. When you travel all through the entire array using index 1 and find no duplications, then use index 2 (provided it's greater than zero) and repeat as necessary with all remaining indexes until the entire array has been removed of all duplicates. Repeat as necessary. If you find any duplicates whatsoever, then set a redo-flag=1.

If redo-flag=1, then you repopulate the radio buttons with values from the array and present the form again to the user with a notice how to correctly do the survey.

If redo-flag=0, then you have traveled all the way through the array with all indexes reporting a value greater than 0 and have found no duplications -- thus, your survey has been correctly reported.

That's the way I would do it -- but, your mileage may vary.

tedd

--
--------------------------------------------------------------------------------
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux