Jump to content


Photo

Can you retain a radio buttons position in an array?


  • Please log in to reply
3 replies to this topic

#1 dmacman

dmacman
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 18 April 2006 - 04:03 PM

Hi All,

I am trying to do several forms with dynamic radio buttons ( I would use checkboxes, but I want to limit them to only one selection per item).

I can build the form dynamically and get the data, but I want to retain the position of the radio button in an array (to insert into my table).

IE...

|---Radio Button 1-|-Radio Button 2--|-Radio Button 3--|
|-----------------------|-----Selected--------|--------------------|

[Radio Button] => Array
(
[0] => 0
[1] => 1
[2] => 0
)


Again, If I could limit the users selection to one checkbox, I would just to pull off this positioning in the array I am trying to achieve.

Is this even possible?

Thanks,

Don

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 April 2006 - 08:18 PM

Don't understand your problem.

Are you having a problem when creating the form and showing the correct button as selected?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 dmacman

dmacman
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 19 April 2006 - 01:46 PM

Hi Barand,

The problem I have is I am making a list of 45 celebrities and creating the 'poll' dynamically. I setup the choices as radio buttons so they can only vote for 1 category. But my table is setup with a different field for each category ( I now know this is not efficient and I am working on an enum field to store the votes).

I could have used checkboxes, but without a javascript snippet, they could chose all the categories (and the checkbox method would make the array easy to store in my current table layout).

What I was trying to do is save the position (of chosen category) and store it in that field along with a 'zero' for the non-chosen categories.

I don't know i that is even possible, but would like to know, just for knowledge sake.

Does that make more sense?

Thanks,

Don

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 02:40 PM

Okay, I think I understood.

Simple give the radio groups different names:

<input type="radio" name="group1" value="value1"> Value 1 for Group 1
<input type="radio" name="group1" value="value2"> Value 2 for Group 1
<input type="radio" name="group1" value="value3"> Value 3 for Group 1

<input type="radio" name="group2" value="value1"> Value 1 for Group 2
<input type="radio" name="group2" value="value2"> Value 2 for Group 2
<input type="radio" name="group2" value="value3"> Value 3 for Group 2

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users