Solved

Dropdown box validation in Coldfusion

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

860 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