Solved

Dropdown box validation in Coldfusion

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

813 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

13 Experts available now in Live!

Get 1:1 Help Now