Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange ???

Status
Not open for further replies.

iggit

Programmer
May 20, 2001
47
US
This is the select:

<select class=&quot;nodata&quot; name=&quot;makesponsorgamelevel&quot;>
<option value=&quot;&quot;>?</option> //ignored
<option value=&quot;red&quot;>Red</option> //100000
<option value=&quot;green&quot;>Green</option> //50000
<option value=&quot;blue&quot;>Blue</option> //25000
<option value=&quot;purple&quot;>Purple</option> //10000
<option value=&quot;black&quot;>Black</option> //5000
</select>

this is the form text field:

<input type=&quot;text&quot; class=&quot;nodata&quot; size=&quot;6&quot; name=&quot;makesponsortotalplayers&quot; onKeyPress=&quot;return numbersonly(this, event)&quot;>

Text field needs to result in a number corresponding
to the color selection from the select list. When the
select list is 'selected' it needs to place the correct
number in the text box (above next to the option).

Is there a script already made to do this? If not, could someone please point me in the direction of a solution?
Thank You

 
Put an onchange event handler in the <SELECT> and use the numbers for values instead of color names, if that fits in with the rest of your site.

Code:
<select class=&quot;nodata&quot; name=&quot;level&quot; onchange=&quot;fillTotalPlayers()&quot;>
<option value=&quot;&quot;>?</option>
<option value=&quot;100000&quot;>Red</option>
<option value=&quot;50000&quot;>Green</option>
<option value=&quot;25000&quot;>Blue</option>
<option value=&quot;10000&quot;>Purple</option>
<option value=&quot;5000&quot;>Black</option>
</select>


Then add a <SCRIPT> like this-
Code:
<SCRIPT>
function fillTotalPlayers(){
   var iOption = document.myForm.level.selectedIndex;
   var howMuch = document.myForm.level.options[iOption].value;
   document.myForm.makesponsortotalplayers.value = howMuch;
}
</SCRIPT>
[code]

That ought to do it.

&quot;Is there a script already made to do this?&quot;

Ready made scripts are handy for utility purposes like validating strings as dates, displaying numbers with two decimal places.  What you want to do is pretty common, but it is only five lines of code counting the braces.  It might be a challenge to devise a procedure for this that could be applied in different contexts.  Maybe you might try that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top