0

Hi I know this was asked many times, I'm looking for a simple solution.

<select onchange="this.options[this.selectedIndex].value">
    <option>--Select--</option>
    <option value="1">One</option>    
<option value="2">Two</option>  
</select>

When a user select an option let's say One the select box would display the numerical 1.

Thanks in advance

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70

2 Answers2

1

Why don't you just use a numeral for the display option on each? e.g. <option value="1">1</option> (and take the inline javascript out entirely).

example: http://jsfiddle.net/79xvY/

  • That is just an example I'm getting the datas from database w/c have long characters but have an abbreviation w/c I'm going to put in the value. – user3457998 May 08 '14 at 03:26
  • To insert a value from a database you'd just write the reference out inline using your server-side language as you wrote out the page HTML. If you were changing the value dynamically, I imagine you'd use the AJAX callback function linked to .onreadystatechange as a trigger to update the – Hector Pirensis May 08 '14 at 03:46
0

This will set the actual innerHTML value of the select box, if that is what your goal is

<select onchange="this.options[this.selectedIndex].innerHTML=this.value">
    <option>--Select--</option>
    <option value="1">One</option>    
    <option value="2">Two</option>  
</select>
The4thIceman
  • 3,709
  • 2
  • 29
  • 36