Advertisement

07.27.2008 at 02:05PM PDT, ID: 23599287
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Trying to add Radio button validation to working javascript validation

Asked by mnoel76 in JavaScript

Tags:

I have a working javascript validation code that I am now trying to add radio button validation to.  I have read through the previous questions but they dont seem to help or I can get it right.  

Here is the header file that is called by the form 'msgform'

<? @session_start(); ?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?
      require_once('Connections/myconn.php');
      mysql_select_db($database_myconn,$myconn);
      $settingsSql = 'select * from settings where id = 1';
      $settingsR = mysql_query($settingsSql,$myconn) or die(mysql_error());
      $settings = mysql_fetch_assoc($settingsR);
      $siteTitle .= ' ';
      if(!isset($siteDescription))
            $siteDescription = $settings['siteDesc'];
      if(!isset($siteKeywords))
            $siteKeywords = $settings['siteKeywords'];
?>            
<title><? echo $siteTitle; ?></title>
<meta name="description" content="<? echo $siteDescription; ?>"/>
<meta name="keywords" content="<? echo $siteKeywords; ?>" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="googlebot" content="index,follow" />
<meta name="msnbot" content="index,follow" />
<meta name="robots" content="index,follow" />
<link href="mystyle.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/calendar/cal2.js"></script>
<script type="text/javascript" src="/calendar/cal_conf2.js"></script>

<script type="text/javascript">

function validate()
{
  var regex = /^[0-9]{5}$/;
  if (regex.test(document.getElementById("zip").value))
    return true;
  alert("Zip Code must be just 5 numbers!");
  return false;
}

function grabZip()
{
     var zip = document.getElementById('zipbox').value;
     if(zip==''){
          alert("You must enter your Zip Code");
          return false;
     }else{
   url =  "map_zipcodes_forsale.php?zip=" + zip;
            poptastic(url);
          return false;
    }
}


function OnSubmitForm()
{
  if(document.pressed == 'Insert')
  {
   document.myform.action ="insert.html";
  }
  else
  if(document.pressed == 'For Rent')
  {
    document.myform.action ="map_zipcodes_rentals.php";
  }
  return true;
}



function poptastic(url){
     newwindow=window.open(url,'MileHighListings', '28','location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=550,left=' + (screen.width - 560) + ',top=0');
     if (window.focus) {newwindow.focus()}
}

function checkForm()
{
   var cname, cemail, cpassword, cpassword2;
   with(window.document.msgform)
   {
      cname    = name;
      cemail   = email;
      cpassword = password;
      cpassword2 = password2;
   }

   if(trim(cname.value) == '')
   {
      alert('Please enter your name');
      cname.focus();
      return false;
   }
   else if(trim(cemail.value) == '')
   {
      alert('Please enter your email');
      cemail.focus();
      return false;
   }
   else if(!isEmail(trim(cemail.value)))
   {
      alert('Email address is not valid');
      cemail.focus();
      return false;
   }
   else if(trim(cpassword.value) == '')
   {
      alert('Please enter a password');
      cpassword.focus();
      return false;
   }
   else if(trim(cpassword2.value) == '')
   {
      alert('Please re-enter a password');
      cpassword2.focus();
      return false;
   }
   else
   {
      cname.value    = trim(cname.value);
      cemail.value   = trim(cemail.value);
      cpassword.value = trim(cpassword.value);
      cpassword2.value = trim(cpassword2.value);
      return true;
   }
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
return regex.test(str);
}




<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>



<style type="text/css">
/*<![CDATA[*/
 div.c10 {color: white; text-align: center; width: 100%}
 div.c9 {width:100%;}
 span.c8 {color: red}
 span.c7 {color: #0000FF}
 div.c6 {border-bottom: 1px solid #666666;}
 input.c5 {cursor: pointer;}
 div.c4 {text-align: left}
 div.c3 {background-color: #0066CC; color: white; text-align: center; width: 100%}
 div.c2 {padding-center:10px;}
 div.c1 {text-align: center}
/*]]>*/
</style>

<style type="text/css">
/*<![CDATA[*/
 div.c4 {color: white; text-align: center; width: 100%}
 div.c3 {text-align: center}
 span.c2 {color: red}
 div.c1 {background-color: #0066CC; color: white; text-align: center; width: 100%}
/*]]>*/
</style>
</head>
<body>
<table width="825" border="0" cellpadding="0" cellspacing="0" align="center" summary="">
<tr>
     <td><div class="c1"><img src="<? echo $settings['header']; ?>" alt="Colorado Homes For Sale and Denver Homes For Rent Listings" title="Colorado Homes For Sale and Denver Homes For Rent Listings" /></div>
<div class="c2" id="Description"></div>
</td>
</tr>
<tr>
<td width="825" bgcolor="#0066CC">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr align="center">
<td height="23"><a href="http://www.milehighlistings.com" class="tabLinkOn">Home</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="buy.php" class="tabLinkOff">Houses For Sale</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="rent.php" class="tabLinkOff">Houses For Rent</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="listing_options.php" class="tabLinkOff">Post A Property</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="open.php" class="tabLinkOff">Open House</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="home_loan.php" class="tabLinkOff">Home Loans</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="resource_center.php" class="tabLinkOff">Resource Center</a></td>
<td width="1" bgcolor="#075441"><img src="/images/pixel.gif" width="1" height="1" alt="" /></td>
<td><a href="memberindex.php" class="tabLinkOn">My Account</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" id="subHeader" summary="">
<tr>
<td align="left"><?
                     if(isset($_SESSION['memberID']) && ($_SESSION['memberID'] != ''))
                        print '<span class="pageText">Welcome </span><span class="pageSubTitle">'.$_SESSION['memberName'].'</span>, <a href="logout.php" class="pageLink">Logout</a>';
                  else
                        print '<a href="register_full.php" class="pageLink">Sign Up Now!</a><span class="pageText"> Already a member? </span> <a href="login.php" class="pageLink">Log In</a>'; ?></td>
<td align="right">
<form action="listingID.php" name="myform" method="post" id="myform">Find by MHL ID: <input name="id" type="text" id="id" size="5" /> <input type="submit" value="Search" /></form>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="mainCell">
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>

        <td id="middleBodyCol">

            <!-- end header -->Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
Here is the code for my form from register_full.php file that calls the checkForm function
 
<form method="POST" name="msgform" action="<?php echo $editFormAction; ?>" onsubmit="return checkForm()">
<br>
  </p> 
  <p align="center" class="pageTitle"><h2><font color="#333366">Create Your Account</font></h2></p>
<p>  * Fields are required </p>
              
      <table border="0" align="center" cellpadding="1" cellspacing="1" class="">
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">* Full Name:</td>
          <td class="rowText"><input type="text" name="name"  size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">* Email:</td>
          <td class="rowText"><input type="text" name="email" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">* Password:</td>
          <td class="rowText"><input type="password" name="password"  size="32" /></td>        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">* Re-enter Password:</td>
          <td class="rowText"><input type="password" name="password2" size="32" /></td>
        </tr>
		    <tr valign="baseline"> 
          <td align="right" valign="middle" nowrap class="colText">* Type of Account:</td>
          <td class="rowText"><input type="radio" name="acctype"  value="realtor" />Realtor/Property Manager/Owner<br />
		                      <input type="radio" name="acctype"  value="renter" />Buyer/Renter</td>
        </tr>
        <td height="1" colspan="2 class="rowText""><hr size="1"></td>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Company Name: (optional)</td>
          <td class="rowText"><input type="text" name="companyname" value="<?php echo $row_memberinfo['companyname']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Address: (optional)</td>
          <td class="rowText"><input type="text" name="address" value="<?php echo $row_memberinfo['address']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">City: (optional)</td>
          <td class="rowText"><input type="text" name="city" value="<?php echo $row_memberinfo['city']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">State: (optional)</td>
          <td class="rowText"><input type="text" name="state" value="<?php echo $row_memberinfo['state']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Zip: (optional)</td>
          <td class="rowText"><input type="text" name="zip" value="<?php echo $row_memberinfo['zip']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Phone: (optional)</td>
          <td class="rowText"><input type="text" name="phone" value="<?php echo $row_memberinfo['phone']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Fax: (optional)</td>
          <td class="rowText"><input type="text" name="fax" value="<?php echo $row_memberinfo['fax']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline"> 
          <td align="right" nowrap class="colText">Company web site: (optional)</td>
          <td class="rowText"><input type="text" name="companywebsite" value="http://www.<?php echo $row_memberinfo['companywebsite']; ?>" size="32" /></td>
        </tr>
        <tr> 
          <td colspan="2" class="colText"><div align="center"></div></td>
        </tr>
        <tr> 
          <td colspan="2" class="rowText"><div align="right"> 
              <input name="active" type="hidden" id="active" value="Yes">
              <input name="Submit22" type="submit"  value="Create Account" >
            </div></td>
        </tr>
        <tr> 
          <td colspan="2"></td>
        </tr>
        <tr> 
          <td colspan="2"></td>
        </tr>
      </table>
 
</table>
 <p>&nbsp;</p>
    <input type="hidden" name="MM_insert" value="msgform">
  <input type="hidden" name="groupid" value="<? echo $_SESSION['memberID']; ?>">
 
  
</form>
[+][-]07.27.2008 at 02:35PM PDT, ID: 22099647

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 03:11AM PDT, ID: 22101819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 04:59AM PDT, ID: 22102233

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: Javascript PHP mySQL
Sign Up Now!
Solution Provided By: mplungjan
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628