Solved

Dropdown box validation in Coldfusion

Posted on 2004-08-25
3
603 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
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…

685 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