Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142100

Set selected display value of select option box

$
0
0

I want to make a selection in my drop down where the display text is different than the actual value. Once I make my selection I want the actual HTML that is displayed in the SELECT box to show the actual value, not the selected text.

I have this so far. It almost works, but once I make the selection, it DOES set the viewable field to the value, but if I click the dropdown a second time the initial selectable choices are no longer there, just the values.

<select size="1" style="width: 28mm; border: 1px solid;"" name="Priority"
        id="Priority" onChange="setDevices(this);">
    <option selected><? print($row[Priority]); ?></option>
    <option value="Pri1">This is Priority 1</option>
    <option value="Pri2">This is Priority 2</option>
    <option value="Pri3">This is Priority 3</option>
    <option value="Pri4">This is Priority 4</option>
</select>

function setDevices(elem) {
    elem.options[elem.selectedIndex].innerHTML = elem.options[elem.selectedIndex].value
}

Viewing all articles
Browse latest Browse all 142100

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>