Sunday 15 July 2012

html - How to access a form drop down from Javascript -


Is there a way to use a drop down option text using Javascript?

For example, by assuming I can access:

  document.getElementById ("transFrom"). Values;  

But I want text between the option tag.

Here's the HTML drop-down for a form:

  & lt; Name = "transFrom" id = "transFrom" style = "width: 300px;" Select Tabindex = "1" onfocus = "valid valid_field (this)" onchange = "valid valid_field (this)" & gt; & Lt; Option value = "" & gt; Choose an account & lt; / Option & gt; & Lt; Option value = "S" & gt; Savings & lt; / Options & gt; & Lt; Option value = "c" & gt; Checking & lt; / Option & gt; & Lt; Option value = "m" & gt; Money market & lt; / Options & gt; & Lt; / Select & gt;  

Try

  document.getElementById (" TransFrom "). Option [document.getElementById ("TransFram"). SelectedIndex] .text  

No comments:

Post a Comment