Solved

Dropdown box validation in Coldfusion

Posted on 2004-08-25
3
580 Views
Last Modified: 2013-12-20
This is probably an easy question for you guys but I'm drawing a blank. I have a form that users submit to me. A couple of the fields are dropdown boxes. eg. The title of the field is Select Your Sport and in the dropdown box is a list of sports. Now i have a javascript that checks to see if different fields are filled in within my form but the dropdowns are where i have my problem. Currently the highlighted selection is "Select Your Sport". If a user fills in all required information but forgets to select their sport, i get an email with the info they submitted but in the sport field it says their sport is "Select Your Sport" and not soccer, football, baseball etc.. How can I make the Select your Sport option visible but validate it somehow so that if no sport is selected they will get a message saying "You must select your sport". Does this make sense? I am using <cfform> and have posted my <cfselect> code below.

<cfselect name="sport" message="You must choose a sport to process an update!" required="yes" multiple="no">
                <option selected>Select Your Sport</option>
      <option value="Football">Football</option>
      <option value="Boys Soccer">Boys Soccer</option>
      <option value="Girls Soccer">Girls Soccer</option>
      <option value="Field Hockey">Field Hockey</option>
      <option value="Girls Volleyball">Girls Volleyball</option>
      <option value="Girls Tennis">Girls Tennis</option>
      <option value="Boys Cross Country">Boys Cross Country</option>
      <option value="Girls Cross Country">Girls Cross Country</option>
      <option value="Boys Golf">Boys Golf</option>
</cfselect>
0
Comment
Question by:IShiva
3 Comments
 
LVL 21

Assisted Solution

by:pinaldave
pinaldave earned 25 total points
ID: 11893080
you can write this code on the submitted page
<cfif form.sport eq 'Select Your Sport'>
You must select your sport
</cfif>

also you need to change your first option like this...   <option value="Select Your Sport"  selected>Select Your Sport</option>

Regards,
---Pinal
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 25 total points
ID: 11894403
You could use pinaldave's solution, but that validation is server side and you probably want it to happen client side - especially since you have other clientside validation.

I would add a javascript function

function CheckSelect()
{
if(f (the_form.sport.selectedIndex == 0)
{

// If the first choice is selected display an alert box
// stating the first choice is not a valid selection
alert("Please select a sport.");

// Focus on the dropdown menu after OK is clicked from the alert box
the_form.sport.focus();
return (false);
}

Then in the form

 onsubmit="return CheckSelect()"
0
 

Author Comment

by:IShiva
ID: 11911774
Thanks for the options guys!

IShiva
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now