View Full Version : Validating Selected Drop Down

05-04-2004, 02:08 PM
Trying to validate Selected drop down in my Cold Fusion for Netscape 4.77 browser:

<!-- <OPTION VALUE="TBD" SELECTED>Select Options:</OPTION> -->
<cfquery name="listNet" datasource="mydatabasename" dbtype="ODBC">
select *
from network_table
<OPTION VALUE="#network#">#network#</OPTION>

I tried this with JavaScript:

function Val()
if(document.myFormName.network.selectedIndex == 0)
alert('Select a network\n');

<cfform action = "myformaction.cfm" name = "myFormName" onSubmit = "return Val();">

The above didnt work. Please advise.

05-04-2004, 03:48 PM
Any time you attempt to integrate ColdFusion's automatic form scripting (via the <cfform> tag), you're asking for ridiculous complications regarding any customized scripting. If you're to use the <cfform> tag, also use the <cf{INPUTTYPE}> tags:

<cfform name="myForm" action="form.cfm">
<cfselect name="mySelect" required="Yes" ... />

Check the docs when you have questions. (http://www.cfdocs.org/cfselect/) Otherwise, dropping the <cfform> tag for the reg'lar old <form> tag leaves your scripting totally up to you. Pass in a reference and it's that much easier.

function Val(evt, f) {
if ( 1 > f.elements['mySelect'].selectedIndex) {
alert('Please select an option.');
return false;
<form action="form.cfm" name="myForm" onsubmit="return Val(event, this);">
<select name="mySelect">

05-04-2004, 04:46 PM

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum