Skip to main content
Inspiring
July 12, 2007
Answered

drop down box

  • July 12, 2007
  • 3 replies
  • 454 views
I have the form with three required fields: center, lastname, and org.
Supposed, user select the dropbox center then enter last name and hit the submit button without select the org code. If it happend then message pop up and they have to select the value from center box but the value from org code they selected at the first time was gone. How do I keep that value? The code I have for text box is worked but when I apply for drop box then it doesn’t.

Thanks
This topic has been closed for replies.
Correct answer
Here's a way that has worked for me.

In the HEAD:

<script>
function checkMenu(theForm, theMenu, theValue) {
if(theValue=="0")
return false;
else
return true;
}
</script>

In the CFFORM:

<cfselect name="Staff"
class="c1"
Required="yes"
Message="You must select a Staff Person"
onValidate="checkMenu">
<OPTION VALUE=0 Selected>-- Please select a Staff Person --
<cfloop query="mncstaff">
<option value="<cfoutput>#mncstaff.mncstaff#</cfoutput>" ><cfoutput>#mncstaff.Last_Name#, #mncstaff.First_Name#</cfoutput></option>
</cfloop>
</cfselect>

3 replies

Correct answer
July 20, 2007
Here's a way that has worked for me.

In the HEAD:

<script>
function checkMenu(theForm, theMenu, theValue) {
if(theValue=="0")
return false;
else
return true;
}
</script>

In the CFFORM:

<cfselect name="Staff"
class="c1"
Required="yes"
Message="You must select a Staff Person"
onValidate="checkMenu">
<OPTION VALUE=0 Selected>-- Please select a Staff Person --
<cfloop query="mncstaff">
<option value="<cfoutput>#mncstaff.mncstaff#</cfoutput>" ><cfoutput>#mncstaff.Last_Name#, #mncstaff.First_Name#</cfoutput></option>
</cfloop>
</cfselect>
kt03Author
Inspiring
July 20, 2007
it worked, thanks alot
Inspiring
July 12, 2007
Then you can do it the hard way, which is to write your own javascript. I learned js by buying the book, "Teach Yourself Javascript in 24 Hours" by SAMS publishing. Alternatively, there are tutorials on the internet.

Just so you know, required="yes" is a useless atttibute for <cfselect>. It will always have a value when you submit the form. It might not be the one you want, but it will have one.
Inspiring
July 12, 2007
The easiest way to handle this is to delete the option tags where the value = 0.
kt03Author
Inspiring
July 12, 2007
I don't want to set it by defaul because I need user to select what they need.