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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating select options before and after selection

Status
Not open for further replies.

lawlerpat

Programmer
Jun 28, 2002
54
US
I have an option object that I need to evaluate the selection of by comparing the original value that was loaded when the page was sent to the new value on changes.

Once the onChange() event occurs, I have lost the original value in object.options[obj.selectedIndex].value

Question: "How can I get the original value loaded into a variable and compare that to the new changed value"

Additional Comments: I created a function for the onFocus event to set the original value, but it seems as it this function is called once originally then as soon as I mouse up on the new selection the onFocus() function is called again thus resetting my origVariable to the new value.

Thanks
 
here's one way:

<html>
<head>
<title>test</title>

<script type=&quot;text/javascript&quot;>
function storeIt(oSel) {
origVal = self.origVal?
self.origVal:
oSel[oSel.selectedIndex].value;
}
function checkIt(oSel) {
var newVal = oSel[oSel.selectedIndex].value;
alert(&quot;origVal = &quot; + origVal +
&quot;\nnewVal = &quot; + newVal);
}
</script>
</head>

<body>
<form>
<select name=&quot;sel&quot; onmousedown=&quot;storeIt(this);&quot; onchange=&quot;checkIt(this);&quot;>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot; selected=&quot;selected&quot;>2</option>
<option value=&quot;3&quot;>3</option>
</select>
</form>
</body>
</html>



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top