Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-04-2012, 02:40 AM   PM User | #1
hayonj
New Coder

 
Join Date: Apr 2012
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
hayonj is an unknown quantity at this point
$_POST['select'] vs document.getElementById('select').options.text

Hi

I need help from the gurus out there.

Basicly what I'm trying to accomplish is :

I have a select form with various options...

For example a drop menu with all the countries.

Each have a value : e.g. 'af' => Afghanistan

I'm basically trying to send the text in between to the options tags to the mysql database.

All I have succeeded up to now is to send the value
E.g: 'af'

I have foun a way to have JavaScript get the name from the options field.

By doing something like :

Var pname = document.getElementById('select').options
Var index = document.getElementById('select').index

Var text = pname['index'].text

Is there any way to do this through PHP ?

I could send the value to a hidden field and retrieve it with $_POST


Any ideas ?

Thanks
hayonj is offline   Reply With Quote
Old 07-04-2012, 04:50 AM   PM User | #2
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,155
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
You can simply this a lot. I'm assuming that you are using PhP to build all your select options, which is what I do. But the value that gets returned in the form is just the index value for that select option. Then PhP can look up whatever information it needs from that array using that index value, which is the same for both the option and the array element.
DrDOS is offline   Reply With Quote
Old 07-04-2012, 06:55 PM   PM User | #3
hayonj
New Coder

 
Join Date: Apr 2012
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
hayonj is an unknown quantity at this point
No I have built the form in my HTML page and getting the values through $_POST
hayonj is offline   Reply With Quote
Old 07-04-2012, 07:46 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Ah, I see that you hijacked another user's thread.
Refer to my answer in this one: http://www.codingforums.com/showthread.php?t=266799 which describes that you must requery it from the provided value. JS itself is capable of swaping the set to provide the results of the displayed text and not the value, but that would be a JS question and not a PHP one. All that matters to PHP is what name=value combinations its received.

As for your vs here, there is no comparison. They are no way similar to each other.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:29 PM.


Advertisement
Log in to turn off these ads.