Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts

    $_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

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,033
    Thanks
    15
    Thanked 240 Times in 240 Posts
    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.

  • #3
    New Coder
    Join Date
    Apr 2012
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts
    No I have built the form in my HTML page and getting the values through $_POST

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •