IT Community - Software Programming, Web Development and Technical Support

checkbox validation

This is a discussion on checkbox validation within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; hi, how to validate checkbox using javascript... advance thanks, Rajkumar...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-14-2007, 04:44 AM
rajkumar rajkumar is offline
D-Web Trainee
 
Join Date: Nov 2007
Posts: 31
rajkumar is on a distinguished road
Default checkbox validation

hi,

how to validate checkbox using javascript...


advance thanks,

Rajkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-14-2007, 05:12 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: checkbox validation

hi rajkumar,

case1:

<script language="javascript" type="text/javascript">
function check() {
if (document.Form1.chk1.checked == true)
alert("Checked");
else
alert("Not Checked");
}
</script>

case2:
<script language="javascript" type="text/javascript">
function check() {
if (document.getElementById("chkId").checked == true)
alert("Checked");
else
alert("Not Checked");
}
</script>
__________________
.......................
Thanks,
Venkatbi...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-15-2007, 02:38 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Cool Re: checkbox validation

Hi,

I hope that, this post will clear ur doubts


Code:
<SCRIPT TYPE="text/javascript" >

function checkCheckBoxes() 
{
  if (document.frmTest.CHKBOX_1.checked == false &&
      document.frmTest.CHKBOX_2.checked == false &&
      document.frmTest.CHKBOX_3.checked == false)
      {
              alert ('You didn\'t choose any of the checkboxes!');
              return false;
       }
       else
      {
              return true;
       }
}

</SCRIPT>


<form onsubmit="return checkCheckBoxes();" action="">
<input type="checkbox" name="CHKBOX_1" value="1">1</p>
<input type="checkbox" name="CHKBOX_2" value="2">2</p>
<input type="checkbox" name="CHKBOX_3" value="3">3</p>
<input type="submit" value="Submit!" />
</form>
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-15-2007, 06:28 AM
rajkumar rajkumar is offline
D-Web Trainee
 
Join Date: Nov 2007
Posts: 31
rajkumar is on a distinguished road
Default Re: checkbox validation

hi,

krishnakumar & venkat thank you very much for ur solution....

with regards,
rajkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-15-2007, 07:43 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: checkbox validation

hi rajkumar,
To check multiple checkbox...
function funCheck()
{
vTmp1=document.myform.getElementsByTagName("checkb oxName");
vInLen=vTmp1.length;



for(vI=0;vI<vInLen;vI++)
{

vRes[vI]=vTmp1.item(vI).getAttribute('checked')
if(vRes[vI]==true)
{

alert("true"+vRes[vI])



}
else
{
alert("false"+vRes[vI])
}




}

}
__________________
.......................
Thanks,
Venkatbi...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-16-2007, 12:32 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Smile Re: checkbox validation

<html>
<head>
<script type="text/javascript">
function validate(form)
{

if (!document.form1.sex[0].checked && !document.form1.sex[1].checked)
{

alert("Please Select Sex");
return false;}


if(!document.form1.agree.checked){alert("Please Read the guidelines and check the box below");
return false;
}


return true;
}
</script>
<body>
<table border='0' width='50%' cellspacing='0' cellpadding='0' >
<form name=form1 method=post action=action_page.php onsubmit='return validate(this)'>
<input type=hidden name=todo value=post>

<tr bgcolor='#ffffff'><td align=center >
<font face='verdana' size='2'><b>Sex</b>
<input type=radio name=sex value='male'>Male </font>
<input type=radio name=sex value='female'>
<font face='verdana' size='2'>Female</font>
</td>
</tr>

<tr>
<td align=center bgcolor='#f1f1f1'>
<font face='verdana' size='2'>
<input type=checkbox name=agree value='yes'>I agree to terms and conditions </td></tr>
<tr bgcolor='#ffffff'>
<td align=center >
<input type=submit value=Submit>
<input type=reset value=Reset>
</td>
</tr>
</table></form>

</body>
</head>
</html>
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count the time in seconds that a checkbox is really checked itbarota HTML, CSS and Javascript Coding Techniques 1 02-13-2008 10:16 PM
I have multi checkbox in my form... gk_cloud PHP Programming 2 10-22-2007 06:31 AM
How to show a table when click a checkbox? S.Vinothkumar HTML, CSS and Javascript Coding Techniques 6 10-12-2007 07:02 AM
client side validation for checkBox using ServerControlButton itbarota HTML, CSS and Javascript Coding Techniques 1 09-26-2007 11:18 AM
How to postback the checkbox value in treeview when each time it is checked ? bluesky ASP and ASP.NET Programming 0 07-16-2007 12:24 AM


All times are GMT -7. The time now is 01:15 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0