Solved

Include a radio group in validation

Posted on 2006-06-12
1
213 Views
Last Modified: 2013-11-18
I have this simple JS and works about 90% ok.

I need to include a part taht will validate a radio group to make sure an option has been selected.



<script language="JavaScript" type="text/JavaScript">


function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

function validateEmail(fieldValue) {
     return (/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/).test(fieldValue);
}


function Validate() {
              document.forma.nombre.value=trim(document.forma.nombre.value)
              if (document.forma.nombre.value.length == 0) {
               alert("Falta Nombre.")
                return(false)               }      

               document.forma.telefono.value=trim(document.forma.telefono.value)
               if (document.forma.telefono.value.length == 0) {
                alert("Falta Telefono.")
                return(false)                  }

        
              if (!validateEmail(document.forma.email.value)) {
           alert("La dirección de correo electrónico no es valida.");
           return false;
               }      




        return(true)
       


}



</script>
0
Comment
Question by:robrodp
[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
1 Comment
 
LVL 10

Accepted Solution

by:
0h4crying0utloud earned 500 total points
ID: 16889117
somn like this should work:

function Validate() {
              document.forma.nombre.value=trim(document.forma.nombre.value)
              if (document.forma.nombre.value.length == 0) {
               alert("Falta Nombre.")
                return(false)              }    

               document.forma.telefono.value=trim(document.forma.telefono.value)
               if (document.forma.telefono.value.length == 0) {
                alert("Falta Telefono.")
                return(false)               }

       
            if (!validateEmail(document.forma.email.value)) {
          alert("La dirección de correo electrónico no es valida.");
          return false;
              }    


         var myOption = -1;
         for (i=document.forma.radioGroupName.length-1; i > -1; i--) {
           if (document.forma.radioGroupName[i].checked) {
             myOption = i;
           }
         }
         if (myOption == -1) {
            alert("You must select a radio button");
            return (false);
         }

        return(true)
       


}
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

617 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