saturation
asked on
Don't fire onChange first time user selects an option
I'm trying to prevent the alert box in OnChange from firing when the page loads and a user selects his or her first option. After the first one selection, I do want the alert in the onChange to fire. This code doesn't seem to be working. Help?
<html>
<head>
<title></title>
<script language="javascript">
function save(i) {
if (i != 0) {
alert("****" + i);
}
i=1;
}
</script>
<BODY bgcolor=edede1 CLASS="MAINBODY" LINK=#003B72 VLINK=#003B72 TOPMARGIN=0 LEFTMARGIN=0">
<form name=form>
<select name="main" size="10" style="width:250px;" onchange="save(i);">
<option value=test></option>
<option value=test2></option>
</select>
</form>
<html>
<head>
<title></title>
<script language="javascript">
function save(i) {
if (i != 0) {
alert("****" + i);
}
i=1;
}
</script>
<BODY bgcolor=edede1 CLASS="MAINBODY" LINK=#003B72 VLINK=#003B72 TOPMARGIN=0 LEFTMARGIN=0">
<form name=form>
<select name="main" size="10" style="width:250px;" onchange="save(i);">
<option value=test></option>
<option value=test2></option>
</select>
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script language="javascript">
// Define Global Variable
var g_IsFirstTime =1;
function DoAction(value) {
if (g_IsFirstTime) {
g_IsFirstTime = 0;
return;
}
// Do Your other actions here
}
</script>
<form>
<select onChange="DoAction(this.va lue);">
<option value="1"> Option 1</option>
<option value="2"> Option 2</option>
</select>
</form>
// Define Global Variable
var g_IsFirstTime =1;
function DoAction(value) {
if (g_IsFirstTime) {
g_IsFirstTime = 0;
return;
}
// Do Your other actions here
}
</script>
<form>
<select onChange="DoAction(this.va
<option value="1"> Option 1</option>
<option value="2"> Option 2</option>
</select>
</form>
<html>
<head>
<title></title>
<script language="javascript">
var i=0;
function save() {
if (i!=0) {
alert("****" + i);
}
i=1;
}
</script>
<BODY bgcolor=edede1 CLASS="MAINBODY" LINK=#003B72 VLINK=#003B72 TOPMARGIN=0 LEFTMARGIN=0">
<form name=form>
<select name="main" size="10" style="width:250px;" onchange="save();">
<option value=test></option>
<option value=test2></option>
</select>
</form>