How extract text from form element using <option>, Javascript extracts the assigned value, how do I get the text? |
How extract text from form element using <option>, Javascript extracts the assigned value, how do I get the text? |
Ann-Marie Foster |
Aug 5 2018, 12:48 AM
Post
#1
|
Group: Members Posts: 7 Joined: 5-August 18 Member No.: 26,686 |
Here is the COUNTRY input of a checkout form.
CODE HTML:- Country <select NAME="Bill Country" ID="BillCountry" ONCHANGE="UpdateCheckout()"> <option value="US">USA</option> <option value="AF">Afghanistan</option> <option value="AL">Albania</option> <option value="DZ">Algeria</option> <option value="AD">Andorra</option> . . . . . . </select> The above displays a form element where the customer can select their country. java script: document.getElementById("BillCountry").value; Gets the 2 character "Country Code" needed by PayPal. But I would like to also access the TEXT of the particular country selected for printing a summary. After they select a country the full text shows on the form element but HOW DO I EXTRACT THE TEXT? |
CharlesEF |
Aug 8 2018, 05:35 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Funny, when I do a bing search (I don't use google for anything) for 'javascript get selected option text' all the main results shows examples like my code sample. In fact, pandy's code sample is the only place I have ever seen that syntax used.
|
pandy |
Aug 9 2018, 12:49 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
You would have seen it twice had you follow my link to the MDN reference.
I have found examples of your way of doing it now, but only at forums and such. |
Lo-Fi Version | Time is now: 26th April 2024 - 09:56 AM |