Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DropDown Validation Function

Posted on 2009-04-09
2
Medium Priority
?
671 Views
Last Modified: 2012-05-06
I have a drop down javascript function that is not working, can anyone assit me in correcting this script or is there a better way to validate both empty text boxes and a dropdown together.
<script language="JavaScript"> 
<!--
     
function validateform(form_groups) { 
var msg = "";
    if (!textvalid(form_groups.p_DisplayName)) msg += "* Unit Identifier\n"; 
    if (!textvalid(form_groups.p_GroupTitle)) msg += "* Command Name\n"; 
    if (!validate.form_groups.p_service.SelectedIndex == 0)) msg += "* Please select a service \n"; 
    if (msg== "") {return true;} 
    
    else {alert("The following fields have errors. Please change them to continue.\n" + msg); return false;} 
 } 
   
function validate(form_groups) 
{ 
   if (form_groups.p_service.selectedIndex.Value = "") 
   { 
       alert("Please select a service") 
       return false; 
    } 
  return true;  
} 
function textvalid(formfield) { 
    if (formfield.value.length != 0) { 
        return true; 
    } 
    return false;
} 
//-->
</script>

Open in new window

0
Comment
Question by:j1haskins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 24107570
syntax error

form_groups.p_service.selectedIndex.Value = ""

should be

if (form_groups.p_service.options[form_groups.p_service.selectedIndex].value == "") ...

or if you have "please seelct"
then use

if (form_groups.p_service.selectedIndex<1) ...

0
 

Author Closing Comment

by:j1haskins
ID: 31568547
I didn't think I had to use the function again within the other funtion. Thank you for the quick reply.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

610 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