Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

get text from dropdown field not the value

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I like to get the text from a dropdown menu and not (as usual) the value of the selection:



The value I get it like this


But what I need is not the value "0" I need the text "ExamplePage" (selected):


How can I get the "ExamplePage" out of it?

Thank's a lot...
 
Sheriff
Posts: 4860
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you submit a form with a select input then it's the 'value' field that gets submitted, not the display text. Which means you cannot get the display text from your PHP code because it is not submitted to your PHP code.

Whatever value you need to have submitted to your PHP code needs to be the value of the value tag.
 
peter meyer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dropdown field is getting generated dynamicly with java script and I have the value and the text according to the value in an array.
Is it possible to access this array with the php file? So I would have the value and the text...?
 
Tim Cooke
Sheriff
Posts: 4860
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript in this context is running client side so has access to the DOM and thus the value and display text of the select input. PHP is server side so does not have access to the DOM and any JavaScript arrays present client side. It only has access to the data submitted from the form inputs, as detailed in my previous answer.
 
peter meyer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim Cook. I always forget to think about the client/server side issue..

But if I would have a hidden input field in my html, would it be possible to store the the text from the selected item  from my dropdown field?
With PHP I could then get the text from the hidden field?
 
Tim Cooke
Sheriff
Posts: 4860
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why so desperate to get the display text server side?

You say you are generating the select inputs dynamically so what about including the display text in the value field as well as the actual display value?


Then server side you can split on the first colon ":" to get the index value and the display text.
 
My, my, aren't you a big fella. Here, have a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic