/    Sign up×
Community /Pin to ProfileBookmark

Form Dropdown Value Checking

I need to check the selected option of a dropdown on change and give an alert if certain values are selected.
The code:

[CODE]<head>
<script type=”text/javascript”>
function warning(){
var val = document.ThisForm.FLEXValue.value;
if(val == 7||val==6||val==5){
alert(“Warning message.”)
}
}
</script>
</head>[/CODE]

I have also tried:
document.FLEXValue.value
document.FLEXValue.selectedIndex
document.ThisForm.FLEXValue.selectedIndex
document.ThisForm.FLEXValue.options[document.ThisForm.FLEXValue.selectedIndex].value
document.FLEXValue.options[document.ThisForm.FLEXValue.selectedIndex].value
The form:

[CODE]<CFFORM METHOD=”POST” ACTION=”FLEXManager.cfm”>
<TR class=”colMain” style=”font-size=14;”>
<TD colspan=”2″ align=”center”>
<BR>
<b>Select Your New FLEX Percentages Here:</b><BR>
<BR>
DOD <—> PIPP<BR>
&nbsp;&nbsp;&nbsp;
<SELECT NAME=”FLEXValue” style=”font-size=16;” onChange=”warning()”>
<cfif GrabEnable.enabled EQ “Y”>
<OPTION value=”7″ <cfif checked EQ “19”>selected</cfif>>4% <—> 0% (code 19)</OPTION>
<OPTION value=”6″ <cfif checked EQ “18”>selected</cfif>>3% <—> 1% (code 18)</OPTION>
<OPTION value=”5″ <cfif checked EQ “17”>selected</cfif>>2% <—> 2% (code 17)</OPTION>
</cfif>
<OPTION value=”1″ <cfif checked EQ “15”>selected</cfif>>0% <—> 3% (code 15)</OPTION>
<OPTION value=”2″ <cfif checked EQ “14”>selected</cfif>>1% <—> 2% (code 14)</OPTION>
<!— <cfif GrabIdle.value LTE 12 AND GrabIdle.value NEQ “”> —>
<cfif GrabEnable.enabled EQ “Y”>
<OPTION value=”3″ <cfif checked EQ “13”>selected</cfif>>2% <—> 1% (code 13)</OPTION>
<OPTION value=”4″ <cfif checked EQ “12”>selected</cfif>>3% <—> 0% (code 12)</OPTION>
</cfif>
</SELECT>
</TD>
</TR>
<TR class=”colMain” style=”font-size=10; font-weight: bold;”>
<TD colspan=”2″ align=”left”>
<UL>
<LI>Changes made today will take effect #DateFormat(GrabActivation.adate,’m/dd/yyyy’)#.</LI>
<LI>If you select Flex Option 17, 18 or 19 you will lose your 45-Day Return privileges.</LI>
</UL>
</TD>
</TR>
<TR class=”colHeader”>
<TD colspan=”2″ align=”right”>
<INPUT TYPE=”SUBMIT” VALUE=”Save Values”>
</TD>
</TR>
<INPUT TYPE=”HIDDEN” NAME=”pacode” value=”#pacode#”>
<INPUT TYPE=”HIDDEN” NAME=”CreateRecord” VALUE=”YES”>
</CFFORM>[/CODE]

But I get the error message document.ThisForm.FLEXValue is null or not an object, and similar messages when I change that part of the function. Please, what am I doing wrong?

Thanks in advance for your help!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@RobDavidAug 16.2006 — not sure if you maybe didn't name your form 'ThisForm'

but i tried this and it worked fine

var tmp, val;

tmp = document.getElementById("FLEXValue");

if(tmp){

val = tmp.options[tmp.selectedIndex].value;

}
Copy linkTweet thisAlerts:
@kodemonkiauthorAug 16.2006 — I did not name my form ThisForm, I thought that's what you used for the form name if there was no name . . . I'm still learning (obviously).

This worked beautifully, thank you so much!
×

Success!

Help @kodemonki spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...