CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Radio button validation (http://www.codingforums.com/showthread.php?t=189641)

jcdevelopment 02-19-2010 07:00 PM

Radio button validation
 
how would i check to see if my radio button is not checked. I know in javascript the term "checked" works. Is there a way to us unchecked?

here is what i am trying to figure out.


Code:

        with (thisform)
  {
  if(document.getElementById('m21').unchecked)
  {
  window.alert('Please Verify Your Age')
  m21.focus();
  return false;}
  }


angst 02-19-2010 07:05 PM

yes, if memory serves me right, you can call your individual radio buttons like an array,

if(document.getElementById('m21')[0].checked == true)

jcdevelopment 02-19-2010 07:15 PM

thanks, that seems it should work, but alas it doesnt, all text fileds work, so should i make it look like the top with?

Code:

with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();
  email.style.border='2px solid red';
  return false;}
  }
               
                with (thisform)
  {
  if(document.getElementById('m21')[0].checked == true)
  {
  window.alert('Please select the state')
  m21.focus();
  return false;}
  }


jcdevelopment 02-19-2010 08:47 PM

if this helps at all, here is the whole code!

Code:

<script type="text/javascript">
function validate_required(field,alerttxt,select)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
 
}

function validate_form(thisform)
{

with (thisform)
  {
  if (validate_required(first_name,"First name must be filled out!")==false)
  {first_name.focus();
  first_name.style.border='2px solid red';
  return false;}
  }
               
                with (thisform)
  {
  if (validate_required(last_name,"Last name must be filled out!")==false)
  {last_name.focus();
  last_name.style.border='2px solid red';
  return false;}
  }
 
                with (thisform)
  {
  if (validate_required(address1,"Address must be filled out!")==false)
  {address1.focus();
  address1.style.border='2px solid red';
  return false;}
  }
 
                with (thisform)
  {
  if (validate_required(phone,"Phone Number must be filled out!")==false)
  {phone.focus();
  phone.style.border='2px solid red';
  return false;}
  }
               
                with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();
  email.style.border='2px solid red';
  return false;}
  }
               
                with (thisform)
  {
  if (validate_required(m21,"Email must be filled out!")==false)
  {m21.focus();
  return false;}
  }
               
               

 
   
  } //last


</script>

Code:

<form name="super_reg" method="post" onsubmit="return validate_form(this)" action="thankyou.php" >
 
  <tr>
  <td colspan="2"><img name="flat_r4_c1" src="images/flat_r4_c1.jpg" width="209" height="105" border="0" id="flat_r4_c1" alt="" /></td>
  <td colspan="2"><img name="flat_r4_c3" src="images/flat_r4_c3.jpg" width="224" height="105" border="0" id="flat_r4_c3" alt="" /></td>
  <td rowspan="3" colspan="5">
  <!-- Start of register div -->
  <div class="register">
 
 
 
                          <div class="wrap_register">
  <p>First Name</p>
  <input name="first_name" type="text" class="long" />
 
  <p>Last Name</p>
  <input name="last_name" type="text" class="long" />
 
  <p>Address</p>
  <input name="address1" type="text" class="long" />
  <input name="address2" type="text" class="long single" />
 
  <p>Phone Number</p>
  <input name="phone" type="text" class="long" />
 
  <p>Email Address</p>
  <input name="email" type="text" class="long" /><br />
 
  <p style="padding-top:5px; display:block;"><input name="m21" type="radio" value="m21" id="m21" /> I Certify That I Am 21 Years Or Older </p>
 
  </div>
 
 
 
 
 
  </div>
  <!-- Start of register div -->
  </td>
  <td><img src="images/spacer.gif" width="1" height="105" border="0" alt="" /></td>
  </tr>
  <tr>
  <td rowspan="2" colspan="2"><img name="flat_r5_c1" src="images/flat_r5_c1.jpg" width="209" height="188" border="0" id="flat_r5_c1" alt="" /></td>
  <td rowspan="2" colspan="2"><img name="flat_r5_c3" src="images/flat_r5_c3.jpg" width="224" height="188" border="0" id="flat_r5_c3" alt="" /></td>
  <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>
  <tr>
  <td><img src="images/spacer.gif" width="1" height="187" border="0" alt="" /></td>
  </tr>
  <tr>
  <td colspan="6"><img src="images/flat_r7_c1.jpg" alt="" name="flat_r7_c1" width="524" height="32" border="0" usemap="#flat_r7_c1Map" id="flat_r7_c1" /></td>
  <td>
 
  <input type="image" src="images/flat_r7_c7.jpg" width="123"  height="32" border="0" alt="SUBMIT!">
 
 
 
 
 
  </td>
  <td colspan="2"><img name="flat_r7_c8" src="images/flat_r7_c8.jpg" width="323" height="32" border="0" id="flat_r7_c8" alt="" /></td>
  <td><img src="images/spacer.gif" width="1" height="32" border="0" alt="" /></td>
  </tr>
 
 
  </form>



All times are GMT +1. The time now is 11:20 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.