Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,179
    Thanks
    174
    Thanked 257 Times in 257 Posts

    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;}
      }

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    yes, if memory serves me right, you can call your individual radio buttons like an array,

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

  • #3
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,179
    Thanks
    174
    Thanked 257 Times in 257 Posts
    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;}
      }

  • #4
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,179
    Thanks
    174
    Thanked 257 Times in 257 Posts
    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>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •