Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2010, 07:00 PM   PM User | #1
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
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;}
  }
jcdevelopment is offline   Reply With Quote
Old 02-19-2010, 07:05 PM   PM User | #2
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
yes, if memory serves me right, you can call your individual radio buttons like an array,

if(document.getElementById('m21')[0].checked == true)
angst is offline   Reply With Quote
Old 02-19-2010, 07:15 PM   PM User | #3
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
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 is offline   Reply With Quote
Old 02-19-2010, 08:47 PM   PM User | #4
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
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>
jcdevelopment is offline   Reply With Quote
Reply

Bookmarks

Tags
buttons, radio, validation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:19 PM.


Advertisement
Log in to turn off these ads.