javascript - How can select specific text value from <select> <option...? -
i want value select option selected text (not option value) in html , javascript?
once able value, wanted specific string 1 below.
value 2.500 , text option value 250 bonus. wanted 250 , assign own input hidden value.
thanks
okay, have given, can guess need option's text.
function getselectedtext(elementid) { var elt = document.getelementbyid(elementid); if (elt.selectedindex == -1) return null; return elt.options[elt.selectedindex].text; }
use way:
var text = getselectedtext('selectid');
or derek suggested, can have in 1 line too:
var text = elementid.queryselector("option:checked").innertext
note: works in modern browsers.
Comments
Post a Comment