...

View Full Version : Validating Selected Drop Down



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



Network<BR>
<P><SELECT MULTIPLE NAME="network">
<!-- <OPTION VALUE="TBD" SELECTED>Select Options:</OPTION> -->
<cfquery name="listNet" datasource="mydatabasename" dbtype="ODBC">
select *
from network_table
</cfquery>
<CFOUTPUT QUERY="listNet">
<OPTION VALUE="#network#">#network#</OPTION>
</CFOUTPUT>
</SELECT>&nbsp;</P>

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.

Choopernickel
05-04-2004, 04: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">
...

florida
05-04-2004, 05:46 PM
Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum