Re: [PHP] Validating Radio Buttons in two directions

2006-02-02 Thread Barry

HiFi Tubes wrote:

Here's the solution I came up with for checking the columns to varify only
one in a column is selected (without using JavaScript) in a matrix of radio
buttons consisting of 4 columns and 4 rows.  Doing this was complicated by
the fact that some rows did not have to be answered. The radio buttons
themselves make sure that only one item is selected in the row so all I had
to deal with was the columns.

Here's what the matrix looks like:

Rank these colors based upon your preference -- 1 is your favorite, 4 is
your least favorite.

Green 1:input type=Radio name=color1 value=1 / 2:input
type=Radio  name=color1 value=2 / 3: input type=Radio
name=color1 value=3 / 4: 3: input type=Radio name=color1 value=4
/

and then do this for three more colors (red, blue, and yellow)  for a 4 by 4
matrix.


First I created an array of answers:  $colorarray = array($color1, $color2,
$color3, $color4);

Next I sorted that array:  arsort($colorarray);
   *Note: This is done to get the empty answers at the end.  After all the
user might only answer for green and yellow in rows 1 and 4.

Next I convert to a string using a blank space as separator:  $colorstring =
implode ($colorarray,  );
*Note:  This is done so that I can remove any rows of questions that the
user did not answer.  Other code makes sure that they have at least answered
one of the four colors.



After that I trim the string of blank spaces: $colorstring =
trim($colorstring);
*Note:  This leaves me with only the questions they have answered,
regardless of whether it is one or four.


also can be done like:
$newArray = $colorarray;
foreach ($colorarray as $key = $value)
  {
if ($value == NULL) unset($newarray[$key]);
  }

Removes every empty arrayfield from your array.

And you don't have to implode and then explode it again.
How you do here:


Now time to go back into an array: $colorarray = explode ( ,
$colorstring);

Next I count how many times particular values show up in an array:
$colorvalues = array_count_values ($colorarray);
   *Note:  This gives me an array with how many times each value shows up.
So if the user selects three items in column 1 of the matrix, the array will
show the key as 1 and the value as 3.

Next I count how many questions have been answered:  $colorcount = count
($colorarray);

With $colorcount and $colorvalue I can then do the following to give the
appropriate error message:

   if ($colorvalues17[1] == '')
 { echo This is not a problem.;}
 else{
 if ($colorvalues[1] 1)
 {echo You have too many colors ranked first (column 1).
Please change your answers so you only have one item in the first
column.;}
 }
   if ($colorvalues17[2] == '')   { echo This is not a problem.;}
 else{
 if ($colorvalues[2] 1)
 {echo You have too many colors ranked second (column 2).
Please change your answers so you only have one item in the second
column.;}
}


1. There is also called a function elseif()
so you dont have to write
if ()
  {
else
  {
if () ..code code..;
  }
  }

just write:
if ()
  {
elseif()
  {
.. code code ..
  }
  }

that's the same.

2. Btw, why can't they rank each color first place O_o ?

3. where does $colorvalues17 come from x_X ?

4. also here can be foreach used
foreach ($colorvalues as $key = $value)
  {
if ($value == 0) echo you rule! no problem!;
elseif ($value = 1) echo Ouch! Just one rank for each color!;
  }


and so on for 3 and 4.  Why the two if - else statements for each column?
The problem was -- remember -- that they don't have to answer all the
questions so I need to make sure there is an answer before I evaluate the
array_count_values to see if it is greater than one.

I suppose that there is a simpler and easier way to do this but I was
pleased that as a newbie I was able to come up with this solution without
expert help.  In addition, with this same set of variables, I was also able
to validate that the user ranked them appropriately. What I mean by this is
that if the person, for example,  answered three of the four, they had to
rank them 1, 2, and 3 and get an error message if they rank them 2, 3, and
4.   The same was done if they rank only 1 or rank only 2 as well.

Yes there is always an easier way.
I would even say, my way can much more be simplyfied, but thats not the 
point.

As long as it works, and the code is ok (who cares?).



I am rather amused by the fact that  the experts were too busy telling me
what to do (even when I said JavaScript was not to be used)instead of
actually helping me learn and come up with a solution.  But, then, I suppose
this problem was too simple for them.   I was tempted to not post my
solution but then I'd be guilty of the same.   I hope this is of some use to
other newbies out there.


You would wonder how much newbies are on this list.
Show me just one PHP expert in here and you get 20 bucks.

Regards
Barry

--
Smileys 

Re: [PHP] Validating Radio Buttons in two directions

2006-02-02 Thread Barry

Barry wrote:

Now time to go back into an array: $colorarray = explode ( ,
$colorstring);

Next I count how many times particular values show up in an array:
$colorvalues = array_count_values ($colorarray);
   *Note:  This gives me an array with how many times each value shows 
up.
So if the user selects three items in column 1 of the matrix, the 
array will

show the key as 1 and the value as 3.

Next I count how many questions have been answered:  $colorcount = count
($colorarray);

With $colorcount and $colorvalue I can then do the following to give the
appropriate error message:

   if ($colorvalues17[1] == '')
 { echo This is not a problem.;}
 else{
 if ($colorvalues[1] 1)
 {echo You have too many colors ranked first (column 1).
Please change your answers so you only have one item in the first
column.;}
 }
   if ($colorvalues17[2] == '')   { echo This is not a problem.;}
 else{
 if ($colorvalues[2] 1)
 {echo You have too many colors ranked second (column 
2).

Please change your answers so you only have one item in the second
column.;}
}



1. There is also called a function elseif()
so you dont have to write
if ()
  {
else
  {
if () ..code code..;
  }
  }

just write:
if ()
  {
elseif()
  {
.. code code ..
  }
  }


sorry small mistake it has to be:
if ()
  {
  }
else
  {
if () { .. code code ..}
  }

just write:
if ()
  {
  }
elseif ()
  {
.. code code ..
  }

Greets
Barry
--
Smileys rule (cX.x)C --o(^_^o)

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



Re: [PHP] Validating Radio Buttons in two directions

2006-02-02 Thread tedd

I am rather amused by the fact that  the experts were too busy telling me
what to do (even when I said JavaScript was not to be used)instead of
actually helping me learn and come up with a solution.  But, then, I suppose
this problem was too simple for them.   I was tempted to not post my
solution but then I'd be guilty of the same.   I hope this is of some use to
other newbies out there.

HiFiTubes


HiFiTubes;

I'm shocked by the fact that you WERE helped and now you say you 
weren't. I spent time writing you four emails outlining how to solve 
your problem.


I did provide you with a working javascript example because you 
cannot detect what the user is doing from server-side.


However, you rejected that solution, so I spent my time reviewing 
your problem and then provided you with a solution that required you 
to understand what an index of any array was -- but you didn't know 
what an index was! So, I told you to check the manuals and figure out 
how to use a loop.


Now after you spend time learning the basics, you want to chastise 
this group because we wouldn't write the code for you? That's pretty 
lame.


I spent a lot of time helping you -- but it will be the last time I will.

You have more to learn than php.

tedd

--

http://sperling.com/

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



Re: [PHP] Validating Radio Buttons in two directions

2006-02-01 Thread HiFi Tubes
Here's the solution I came up with for checking the columns to varify only
one in a column is selected (without using JavaScript) in a matrix of radio
buttons consisting of 4 columns and 4 rows.  Doing this was complicated by
the fact that some rows did not have to be answered. The radio buttons
themselves make sure that only one item is selected in the row so all I had
to deal with was the columns.

Here's what the matrix looks like:

Rank these colors based upon your preference -- 1 is your favorite, 4 is
your least favorite.

Green 1:input type=Radio name=color1 value=1 / 2:input
type=Radio  name=color1 value=2 / 3: input type=Radio
name=color1 value=3 / 4: 3: input type=Radio name=color1 value=4
/

and then do this for three more colors (red, blue, and yellow)  for a 4 by 4
matrix.


First I created an array of answers:  $colorarray = array($color1, $color2,
$color3, $color4);

Next I sorted that array:  arsort($colorarray);
   *Note: This is done to get the empty answers at the end.  After all the
user might only answer for green and yellow in rows 1 and 4.

Next I convert to a string using a blank space as separator:  $colorstring =
implode ($colorarray,  );
*Note:  This is done so that I can remove any rows of questions that the
user did not answer.  Other code makes sure that they have at least answered
one of the four colors.

After that I trim the string of blank spaces: $colorstring =
trim($colorstring);
*Note:  This leaves me with only the questions they have answered,
regardless of whether it is one or four.

Now time to go back into an array: $colorarray = explode ( ,
$colorstring);

Next I count how many times particular values show up in an array:
$colorvalues = array_count_values ($colorarray);
   *Note:  This gives me an array with how many times each value shows up.
So if the user selects three items in column 1 of the matrix, the array will
show the key as 1 and the value as 3.

Next I count how many questions have been answered:  $colorcount = count
($colorarray);

With $colorcount and $colorvalue I can then do the following to give the
appropriate error message:

   if ($colorvalues17[1] == '')
 { echo This is not a problem.;}
 else{
 if ($colorvalues[1] 1)
 {echo You have too many colors ranked first (column 1).
Please change your answers so you only have one item in the first
column.;}
 }
   if ($colorvalues17[2] == '')   { echo This is not a problem.;}
 else{
 if ($colorvalues[2] 1)
 {echo You have too many colors ranked second (column 2).
Please change your answers so you only have one item in the second
column.;}
}

and so on for 3 and 4.  Why the two if - else statements for each column?
The problem was -- remember -- that they don't have to answer all the
questions so I need to make sure there is an answer before I evaluate the
array_count_values to see if it is greater than one.

I suppose that there is a simpler and easier way to do this but I was
pleased that as a newbie I was able to come up with this solution without
expert help.  In addition, with this same set of variables, I was also able
to validate that the user ranked them appropriately. What I mean by this is
that if the person, for example,  answered three of the four, they had to
rank them 1, 2, and 3 and get an error message if they rank them 2, 3, and
4.   The same was done if they rank only 1 or rank only 2 as well.

I am rather amused by the fact that  the experts were too busy telling me
what to do (even when I said JavaScript was not to be used)instead of
actually helping me learn and come up with a solution.  But, then, I suppose
this problem was too simple for them.   I was tempted to not post my
solution but then I'd be guilty of the same.   I hope this is of some use to
other newbies out there.

HiFiTubes


Re: [PHP] Validating Radio Buttons in two directions

2006-01-19 Thread Richard Lynch
On Mon, January 16, 2006 9:16 pm, HiFi Tubes wrote:
 I'm kind of a newbie so speak sowly.

 I've got a problem with validating radio buttons that seems to be
 harder
 than I think to solve.   I've got ten items set up like this:

 Green: input type=Radio name=color1 value=1 / input
 type=Radio
 name=color1 value=2 / input type=Radio name=color1 value=3
 /
 and son on out to 10.

Doesn't answer your question, but you really should use:
name=color[1] to keep your sanity when you process these in PHP...

Or, honestly, I'd use name=green or name=color[green] so I knew
green was green instead of having to memorize (or, in my case, FAIL to
memorize) that 1 means green.

 Then I've got Red: input type=Radio name=color2 value=1 / and
 so on
 out to ten again.

 So I've got ten colors each with 10 radio buttons so that they can be
 ranked
 from 1 to 10.  The problem?  Well, obviously, the user can only pick
 one
 value in the row for each color.  That part is simple.  BUT  I also
 need to
 make sure that they only rank one color with the value 1 and, of
 course,
 only one color can have 2 and so on.  How do I validate this so that
 they
 get a warning before they submit that user has picked more one color
 with
 the same ranking?

If you want the warning before they submit, and if you accept the fact
that there is no inherent HTML widget to do that (there isn't) then
your options are all client-side, and have nothing to do with PHP at
all, really, so you're asking in the wrong place...

That said, I'll be polite (this time) and suggest some areas for
research.

#1. Javascript
You can use Javascript to check whatever fields/attributes you want.
Note that the user can turn off or bypass Javascript and submit
invalid info, so you STILL need to run the check again server-side to
be SURE you have valid data.

#2. Flash
You could maybe make a much nicer color-coded fancy interface in Flash.
I HATE flash personally, but depending on your user-base, it might be
appropriate...
I doubt it, but it might be :-)

 An additional complication:  They don't have to answer or rank all the
 colors.  All they really need to do is rank one color to copmplete the
 question.

 I created an array with the answers and then used array_count_values
 to find
 out the frequency but that chokes on color rankings that are left
 blank.

Chokes how?...

If they select nothing at all for one of your colors, then nothing
gets sent for that color to the web-server.  That's just how HTTP/HTML
works.

So if you assumed that $color2 would have some value, and they clicked
on no radio button at all, it won't.

Note also that this is a pretty bad interface in that they could click
on, say, red #3 and then decide they didn't want to pick red at all,
and they are SCREWED -- You have given them no way to change their
mind and say no input to $color2 in the radio buttons, and once you
click any radio button, you are stuck with at least one of them
clicked.

 How do I assure that only one color is ranked at any one value?

 I hope my question makes sense.  Any help will be appreciated.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-19 Thread Richard Lynch
On Tue, January 17, 2006 9:45 am, John Nichel wrote:
 Huh?  Maybe I'm just not awake this morning and not understanding what
 you're trying to explain, but if you're using *radio* buttons, only
 *one* of the same name can be checked at any give time.  ie:

 input type=radio name=color value=1 / Blue
 input type=radio name=color value=2 / Red
 input type=radio name=color value=3 / Black
 input type=radio name=color value=4 / Green
 input type=radio name=color value=5 / Mauve

 If you click Red and Blue is already selected, Blue will
 automatically be unselected.  It's basic HTML.

He has:
   v v v v v
  Red: 1 2 3 4 5
Green: 1 2 3 4 5
 Blue: 1 2 3 4 5

Only one (1) Red may be checked, by radio button rules.

In addition, he needs to constrain that at most one (1) of each digit
may be checked, and therein lies the rub.

VALID INPUTS:

  Red: 1
Green: 3
 Blue: 2

  Red: 1


INVALID INPUTS:

  Red: 1
  Red: 2

  Red: 1
Green: 1


Radio buttons can avoid either of the two above invalid inputs.

They cannot cover both.

He has chosen to cover the first one with Radio Buttons.

The second constraint will then require Javascript (or other
client-side logic) and PHP application logic (since client-side can be
bypassed by user).

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-19 Thread HiFi Tubes
On 1/19/06, Richard Lynch [EMAIL PROTECTED] wrote:

 On Mon, January 16, 2006 9:16 pm, HiFi Tubes wrote:
  I'm kind of a newbie so speak sowly.
 
  I've got a problem with validating radio buttons that seems to be
  harder
  than I think to solve.   I've got ten items set up like this:
 
  Green: input type=Radio name=color1 value=1 / input
  type=Radio
  name=color1 value=2 / input type=Radio name=color1 value=3
  /
  and son on out to 10.

 Doesn't answer your question, but you really should use:
 name=color[1] to keep your sanity when you process these in PHP...

 Or, honestly, I'd use name=green or name=color[green] so I knew
 green was green instead of having to memorize (or, in my case, FAIL to
 memorize) that 1 means green.


These are example questions and values.  The actual values are numerical
since it is a ranking so 1 means 1 (or first) in the results.

 Then I've got Red: input type=Radio name=color2 value=1 / and
  so on
  out to ten again.
 
  So I've got ten colors each with 10 radio buttons so that they can be
  ranked
  from 1 to 10.  The problem?  Well, obviously, the user can only pick
  one
  value in the row for each color.  That part is simple.  BUT  I also
  need to
  make sure that they only rank one color with the value 1 and, of
  course,
  only one color can have 2 and so on.  How do I validate this so that
  they
  get a warning before they submit that user has picked more one color
  with
  the same ranking?

 If you want the warning before they submit, and if you accept the fact
 that there is no inherent HTML widget to do that (there isn't) then
 your options are all client-side, and have nothing to do with PHP at
 all, really, so you're asking in the wrong place...

 That said, I'll be polite (this time) and suggest some areas for
 research.

 #1. Javascript
 You can use Javascript to check whatever fields/attributes you want.
 Note that the user can turn off or bypass Javascript and submit
 invalid info, so you STILL need to run the check again server-side to
 be SURE you have valid data.

 #2. Flash
 You could maybe make a much nicer color-coded fancy interface in Flash.
 I HATE flash personally, but depending on your user-base, it might be
 appropriate...
 I doubt it, but it might be :-)


Neither of these are options my client wants -- no plug-ins even Flash and I
need to allow that JS may not be on.

 An additional complication:  They don't have to answer or rank all the
  colors.  All they really need to do is rank one color to copmplete the
  question.
 
  I created an array with the answers and then used array_count_values
  to find
  out the frequency but that chokes on color rankings that are left
  blank.

 Chokes how?...


Here's the error message:

*Warning*: array_count_values(): Can only count STRING and INTEGER values!
in */home/www/test/test.php* on line *206*


If they select nothing at all for one of your colors, then nothing
 gets sent for that color to the web-server.  That's just how HTTP/HTML
 works.

 So if you assumed that $color2 would have some value, and they clicked
 on no radio button at all, it won't.


I'm not including all my code here...I'm trying to keep it simple so I can
get at the main issue.  As you noted below I'm trying to validate in two
directions or as you say below, I'm trying to cover both...the radio buttons
take care of it one way (the row) and I'm trying to figure out how to do it
for the column as well.

Note also that this is a pretty bad interface in that they could click
 on, say, red #3 and then decide they didn't want to pick red at all,
 and they are SCREWED -- You have given them no way to change their
 mind and say no input to $color2 in the radio buttons, and once you
 click any radio button, you are stuck with at least one of them
 clicked.


They do have the option to change their answers once they submit and get a
message saying one of the required questions is not filled in. I also give
them what answers they have supplied previously.  I do this for the radio
buttons as well.

 How do I assure that only one color is ranked at any one value?
 
  I hope my question makes sense.  Any help will be appreciated.

 --
 Like Music?
 http://l-i-e.com/artists.htm





Re[2]: [PHP] Validating Radio Buttons in two directions

2006-01-18 Thread Steve Clay
Tuesday, January 17, 2006, 11:33:18 PM, HiFi Tubes wrote:
 Thanks to all of you who responded.  Yes, I am doing the grid --basically
 100 radio buttons, that is ten comments that must be ranked from 1 to 10.

Ugh.  If you absolutely can't use Javascript, here's an idea:
Present this question by itself as two lists: on top an unordered list of
options, on bottom an ordered list (initially empty).  Each item will have a
set of links (icons maybe) to place this item next (if in the top list)
or move up/down or remove the item (if in the ordered list).  The user
would click the links to move around the choices until he/she is ready to
submit that question:

add items: _eggs_ , _milk_

1 candy _remove_
2
3

--

1 candy _remove_  _down_
2 eggs  _remove_ _up_ _down_
3 milk  _remove_ _up_

The nice thing is, each page you generate would be a valid response so you,
nor the user, has to worry about, eg. submitting two items in 3rd place.
It would also be /much/ simpler for the user to rearrange items since
he/she no longer has the burden of renumbering each choice.

You could potentially add Javascript onto this setup so that the movement
would be updated purely on the page or with only a minimal XMLHTTPRequest
call.

Another idea: just require Javascript and save yourself reinventing the
wheel. http://www.phpsurveyor.org/index.php is a mature survey system with
ranking question types and nice data export options.

Steve
-- 
http://mrclay.org/

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-18 Thread tedd

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread tedd

How do I assure that only one color is ranked at any one value?

I hope my question makes sense.  Any help will be appreciated.

Thanks in advance.

HiFi Tubes


HiFi:

I understand your problem, you don't want the user to pick a color 
such that it ranks the same as another color (i.e., only one gets a 
number-one ranking, only one gets a number-two ranking and so on).


In php you can detect what the user picked AFTER they submit the form 
(click submit) and then redirect them back with an explanation Hey, 
you made a mistake -- this is what you are supposed to do. And then, 
hope they do it right next time. However, that's against normal (or 
at least my) GUI.


IMO, what you need to do is client-side checking, namely javascript. 
You need to have a routine that checks what the user selects as the 
user selects it -- this can't be done in php -- it can only be done 
server-side.


I give you a hint, you should investigate:

input TYPE=radio NAME=button onClick=whatever/td

The routine should simply un-check a previously checked button.

HTH's

tedd

--

http://sperling.com/

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread John Nichel

tedd wrote:

How do I assure that only one color is ranked at any one value?

I hope my question makes sense.  Any help will be appreciated.

Thanks in advance.

HiFi Tubes



HiFi:

I understand your problem, you don't want the user to pick a color such 
that it ranks the same as another color (i.e., only one gets a 
number-one ranking, only one gets a number-two ranking and so on).


In php you can detect what the user picked AFTER they submit the form 
(click submit) and then redirect them back with an explanation Hey, you 
made a mistake -- this is what you are supposed to do. And then, hope 
they do it right next time. However, that's against normal (or at least 
my) GUI.


IMO, what you need to do is client-side checking, namely javascript. You 
need to have a routine that checks what the user selects as the user 
selects it -- this can't be done in php -- it can only be done server-side.


I give you a hint, you should investigate:

input TYPE=radio NAME=button onClick=whatever/td

The routine should simply un-check a previously checked button.

HTH's

tedd



Huh?  Maybe I'm just not awake this morning and not understanding what 
you're trying to explain, but if you're using *radio* buttons, only 
*one* of the same name can be checked at any give time.  ie:


input type=radio name=color value=1 / Blue
input type=radio name=color value=2 / Red
input type=radio name=color value=3 / Black
input type=radio name=color value=4 / Green
input type=radio name=color value=5 / Mauve

If you click Red and Blue is already selected, Blue will 
automatically be unselected.  It's basic HTML.


--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread Austin Denyer

On Tue, 17 Jan 2006 10:45:01 -0500
John Nichel [EMAIL PROTECTED] wrote:
 
 Huh?  Maybe I'm just not awake this morning and not understanding
 what you're trying to explain, but if you're using *radio* buttons,
 only *one* of the same name can be checked at any give time.  ie:
 
 input type=radio name=color value=1 / Blue
 input type=radio name=color value=2 / Red
 input type=radio name=color value=3 / Black
 input type=radio name=color value=4 / Green
 input type=radio name=color value=5 / Mauve
 
 If you click Red and Blue is already selected, Blue will 
 automatically be unselected.  It's basic HTML.

That's not what he's trying to do.  Grab some coffee #;-D

If I understand correctly, he wants a grid of radio buttons.  Each
color can be ranked 1 through 10.

So, 
In the range of radio buttons for Blue, you can pick 1-10.
In the range of radio buttons for Red, you can pick 1-10.
In the range of radio buttons for Black, you can pick 1-10.
Etc.

He wants something that prevents someone from selecting, say, 2 for Red
if they have already selected 2 for Blue.

It would be easy to validate this after submission and return to the
page if the user screwed up, but for on-the-fly idiot-proofing he's
gonna need JavaScript.

Regards,
Ozz.


pgpHe15uSjLQc.pgp
Description: PGP signature


Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread John Nichel

Austin Denyer wrote:

On Tue, 17 Jan 2006 10:45:01 -0500
John Nichel [EMAIL PROTECTED] wrote:


Huh?  Maybe I'm just not awake this morning and not understanding
what you're trying to explain, but if you're using *radio* buttons,
only *one* of the same name can be checked at any give time.  ie:

input type=radio name=color value=1 / Blue
input type=radio name=color value=2 / Red
input type=radio name=color value=3 / Black
input type=radio name=color value=4 / Green
input type=radio name=color value=5 / Mauve

If you click Red and Blue is already selected, Blue will 
automatically be unselected.  It's basic HTML.



That's not what he's trying to do.  Grab some coffee #;-D

If I understand correctly, he wants a grid of radio buttons.  Each
color can be ranked 1 through 10.

So, 
In the range of radio buttons for Blue, you can pick 1-10.

In the range of radio buttons for Red, you can pick 1-10.
In the range of radio buttons for Black, you can pick 1-10.
Etc.

He wants something that prevents someone from selecting, say, 2 for Red
if they have already selected 2 for Blue.


A, now that makes more sense. (shut-up Jay)

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread tedd

On Tue, 17 Jan 2006 10:45:01 -0500
John Nichel [EMAIL PROTECTED] wrote:


 Huh?  Maybe I'm just not awake this morning and not understanding
 what you're trying to explain, but if you're using *radio* buttons,
 only *one* of the same name can be checked at any give time.  ie:

 input type=radio name=color value=1 / Blue
 input type=radio name=color value=2 / Red
 input type=radio name=color value=3 / Black
 input type=radio name=color value=4 / Green
 input type=radio name=color value=5 / Mauve

 If you click Red and Blue is already selected, Blue will
 automatically be unselected.  It's basic HTML.


That's not what he's trying to do.  Grab some coffee #;-D



Thanks Ozz -- I was not in the mood to be wrong (again -- too much lately).

When I was confronted with a similar problem before, I used html/php/js:

input type=radio name=alter onClick=return uncheckall(?php 
echo($what_button); ?)


Where the javascript was:

script language=javascript

function uncheckall(num)
{
var els=document.forms[0].elements;
for ( i=els.length; i--; )
{
if( els[i].type.toLowerCase() == 'radio' )
{
if (i != num)
{
els[i].checked = false;
}
}
}
els[num].checked = true;
document.alter; return false;
}
/script

That way, when the user clicks any rank, all of the buttons within 
that rank are unchcecked leaving only the most current checked.


tedd

--

http://sperling.com/

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



Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread HiFi Tubes
Thanks to all of you who responded.  Yes, I am doing the grid --basically
100 radio buttons, that is ten comments that must be ranked from 1 to 10.

 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.

John, you said this could easily be done by returning to the page -- that is
what I am doing for the validation of the other questions on this page of
the survey.  My question, then, is how do I validate this grid of radio
buttons in php without using Javascript and remember, too, that the user
only has to answer one question so I have to deal with possible numerous
null or no responses within the  grid of radio buttons.  They might rank
only one color and that would be okay or they might rank any number between
1 and 10.

(Additional note -- I am already carrying their responses over when they
submit the page so that any radio buttons selected are still selected when
the page shows up again after submitting.)

Again, thanks so much for the help so far but I'd like to keep this in php
if I could.

HiFi Tubes

On 1/17/06, tedd [EMAIL PROTECTED] wrote:

 On Tue, 17 Jan 2006 10:45:01 -0500
 John Nichel [EMAIL PROTECTED]  wrote:
 
   Huh?  Maybe I'm just not awake this morning and not understanding
   what you're trying to explain, but if you're using *radio* buttons,
   only *one* of the same name can be checked at any give time.  ie:
 
   input type=radio name=color value=1 / Blue
   input type=radio name=color value=2 / Red
   input type=radio name=color value=3 / Black
   input type=radio name=color value=4 / Green
   input type=radio name=color value=5 / Mauve
 
   If you click Red and Blue is already selected, Blue will
   automatically be unselected.  It's basic HTML.
 
 That's not what he's trying to do.  Grab some coffee #;-D


 Thanks Ozz -- I was not in the mood to be wrong (again -- too much
 lately).

 When I was confronted with a similar problem before, I used html/php/js:

 input type=radio name=alter onClick=return uncheckall(?php
 echo($what_button); ?)

 Where the javascript was:

 script language=javascript

 function uncheckall(num)
{
var els=document.forms[0].elements;
for ( i=els.length; i--; )
{
if( els[i].type.toLowerCase() == 'radio' )
{
if (i != num)
{
els[i].checked = false;
}
}
}
els[num].checked = true;
document.alter; return false;
}
 /script

 That way, when the user clicks any rank, all of the buttons within
 that rank are unchcecked leaving only the most current checked.

 tedd

 --
 

 http://sperling.com/

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




Re: [PHP] Validating Radio Buttons in two directions

2006-01-17 Thread HiFi Tubes
Oops I should have said Austin not John below.  Austin, could you or someone
point my in the direction of how to do this in PHP?

Thanks so much.

HiFi Tubes


On 1/17/06, HiFi Tubes [EMAIL PROTECTED] wrote:

 Thanks to all of you who responded.  Yes, I am doing the grid --basically
 100 radio buttons, that is ten comments that must be ranked from 1 to 10.

  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.

 John, you said this could easily be done by returning to the page -- that
 is what I am doing for the validation of the other questions on this page of
 the survey.  My question, then, is how do I validate this grid of radio
 buttons in php without using Javascript and remember, too, that the user
 only has to answer one question so I have to deal with possible numerous
 null or no responses within the  grid of radio buttons.  They might rank
 only one color and that would be okay or they might rank any number between
 1 and 10.

 (Additional note -- I am already carrying their responses over when they
 submit the page so that any radio buttons selected are still selected when
 the page shows up again after submitting.)

 Again, thanks so much for the help so far but I'd like to keep this in php
 if I could.

 HiFi Tubes

  On 1/17/06, tedd [EMAIL PROTECTED] wrote:
 
  On Tue, 17 Jan 2006 10:45:01 -0500
  John Nichel  [EMAIL PROTECTED]  wrote:
  
Huh?  Maybe I'm just not awake this morning and not understanding
what you're trying to explain, but if you're using *radio* buttons,
only *one* of the same name can be checked at any give time.  ie:
  
input type=radio name=color value=1 / Blue
input type=radio name=color value=2 / Red
input type=radio name=color value=3 / Black
input type=radio name=color value=4 / Green
input type=radio name=color value=5 / Mauve
  
If you click Red and Blue is already selected, Blue will
automatically be unselected.  It's basic HTML.
  
  That's not what he's trying to do.  Grab some coffee #;-D
 
 
  Thanks Ozz -- I was not in the mood to be wrong (again -- too much
  lately).
 
  When I was confronted with a similar problem before, I used html/php/js:
 
  input type=radio name=alter onClick=return uncheckall(?php
  echo($what_button); ?)
 
  Where the javascript was:
 
  script language=javascript
 
  function uncheckall(num)
 {
 var els=document.forms[0].elements;
 for ( i=els.length; i--; )
 {
 if( els[i].type.toLowerCase() == 'radio' )
 {
 if (i != num)
 {
 els[i].checked = false;
 }
 }
 }
 els[num].checked = true;
 document.alter; return false;
 }
  /script
 
  That way, when the user clicks any rank, all of the buttons within
  that rank are unchcecked leaving only the most current checked.
 
  tedd
 
  --
  
 
  http://sperling.com/
 
  --
  PHP General Mailing List ( http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



[PHP] Validating Radio Buttons in two directions

2006-01-16 Thread HiFi Tubes
I'm kind of a newbie so speak sowly.


I've got a problem with validating radio buttons that seems to be harder
than I think to solve.   I've got ten items set up like this:

Green: input type=Radio name=color1 value=1 / input type=Radio
name=color1 value=2 / input type=Radio name=color1 value=3 /
and son on out to 10.

Then I've got Red: input type=Radio name=color2 value=1 / and so on
out to ten again.

So I've got ten colors each with 10 radio buttons so that they can be ranked
from 1 to 10.  The problem?  Well, obviously, the user can only pick one
value in the row for each color.  That part is simple.  BUT  I also need to
make sure that they only rank one color with the value 1 and, of course,
only one color can have 2 and so on.  How do I validate this so that they
get a warning before they submit that user has picked more one color with
the same ranking?

An additional complication:  They don't have to answer or rank all the
colors.  All they really need to do is rank one color to copmplete the
question.

I created an array with the answers and then used array_count_values to find
out the frequency but that chokes on color rankings that are left blank.

How do I assure that only one color is ranked at any one value?

I hope my question makes sense.  Any help will be appreciated.

Thanks in advance.

HiFi Tubes

a retro kinda' guy who values quality over convenience