Solved

re: multiple variables in simple form validation script

Posted on 2008-10-09
2
192 Views
Last Modified: 2011-08-18
I've got 2 text fields -

1. attorney_name
2. attorney_phoneNumber

i need both to be filled out if my radio button:

attorney_representation - Yes

is checked.

i have a working script for 1 of the fields (attorney_name) but i need to add the other (attorney_phoneNumber)


function getRadialValue(strFieldName){

    var objFormField = document.forms[0].elements[strFieldName]

    intControlLength = objFormField.length

    for (i=0;i<intControlLength;i++){

         if(objFormField[i].checked){

                   strValue = objFormField[i].value;

                   return strValue;

         }

    }    

}

function validate(theForm){

      if(getRadialValue('attorney_representation')=='Yes'){

            if(theForm.attorney_name.value==''){

                  alert('Please enter Attorney Name');

            return false;

            }

      }

}

Open in new window

0
Comment
Question by:phillystyle123
2 Comments
 
LVL 3

Accepted Solution

by:
DerkArts earned 250 total points
ID: 22682716
Is there any reason no to do this:  ?
function getRadialValue(strFieldName){

    var objFormField = document.forms[0].elements[strFieldName]

    intControlLength = objFormField.length

    for (i=0;i<intControlLength;i++){

         if(objFormField[i].checked){

                   strValue = objFormField[i].value;

                   return strValue;

         }

    }    

}

function validate(theForm){

      if(getRadialValue('attorney_representation')=='Yes'){

            if(theForm.attorney_name.value==''){

                  alert('Please enter Attorney Name');

            return false;

            }

             if(theForm.attorney_phoneNumber.value==''){

                  alert('Please enter Attorney Phone number');

            return false;

            }

      }

}

Open in new window

0
 

Author Closing Comment

by:phillystyle123
ID: 31504843
DerkArts - will you accept my proposal for marriage? ;-)
 thanks so much - i've been working on this way too long today - much appreciated
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can display objects ? 3 20
Animated .jpg? 13 57
Change text to radio button and calendar form 2 32
how can apply the following conditionals: 4 2
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now