Forum Moderators: coopster

Message Too Old, No Replies

Check Radio Button value

         

Superbuis1

5:03 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



Hello!

This is my current situation: I retrieve data from a database through XML files. The first xml file parses a couple of delivery addresses. The user has to select one of these adresses to continue. Depending on that particular address an order can be made on another page. My question is: How can I get the selected address. With other words. How can I get the address that belongs to the selected radio button? Ofcourse each delivery address has an unique ID, but I don't show this to the user. Should I perhaps first save all the address information in an array? And later in the order page loop through this array to check for the selected radio button? How do I do this exactly? Has anyone a clear example?

Thanks in advance!
Jacco

RonPK

5:23 pm on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not use the unique ID as the radio button's value?

<label for="bt321">
<input type="radio" name="addressID[]" id="bt321" value="321">address description herw
</label>

Or is it top secret?

Superbuis1

5:42 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



Hello Ron,

Yes, perhaps that will work and it's not that secret. But can I use the unique ID infinit? Because I don't know how many delivery addresses I retrieve from the database. The number of radio buttons depends on the number of addresses I retrieve....

Regards,
Jacco

RonPK

11:30 pm on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AFAIK there is no limit to the number of number of radio buttons. Your users may appreciate a not too large number, though...

Superbuis1

4:19 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



Hello Ron,

I think I misunderstood your previous post :). I thought you ment a unique ID generated by php, but you mean the ID I retrieve from the database. Stupid :). Sounds like a good approach to me. I will try this! Thanks!

Regards,
Jacco

Superbuis1

9:47 am on Mar 17, 2004 (gmt 0)

10+ Year Member



I finally got it working! I'm rather new to php so it took some time :) I didn't use the label for option by the way. It's not a demand to get it working I found out. Does it have purpose in this case? Perhaps for my next question: what if I want to sent the other address information also to the next page? It's ok for me to just put it in the AddressID[1] position in the array (if this is possible ofcourse). It now put the value of my key in Address[0] and that's perfect! So is it possible to add another row with the reference information to the address?

Superbuis1

10:41 am on Mar 17, 2004 (gmt 0)

10+ Year Member



Sorry, I found the solution: use an hidden input :)

coopster

11:39 am on Mar 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Right on. Good job.

>>I didn't use the label for option by the way. It's not a demand to get it working I found out. Does it have purpose in this case?

When a LABEL [w3.org] element receives focus, it passes the focus on to its associated control (you can click the text next to a radio button, for example, and the button will be selected).

Labels may be rendered by user agents in a number of ways (e.g., visually, read by speech synthesizers, etc.) This is good in that your pages are accessible to all individuals, including those with disabilities.

Superbuis1

1:38 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



Hmm, that's an interesting thing... I tried, but it works partly. If I select a text next to a radio button, the last radio button will be selected al the time. Do you know why?

RonPK

2:02 pm on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure the for-attribute matches the button's ID:

<label for="bt321">
<input type="radio" name="addressID[]" id="bt321" value="321">address description here
</label>

<label for="bt322">
<input type="radio" name="addressID[]" id="bt322" value="322">address description here
</label>

[et cetera]

Superbuis1

2:44 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



Oh, that's the problem! Thanks. Then I have to create var names in the for loop because I don't know how many radio buttons I get...