Solved

Select/Deselect checkbox using javascript

Posted on 2004-09-30
4
800 Views
Last Modified: 2008-01-09
I have a program that I need to do:

When the user click on a 'checkbox', if one of the value is abnormal, the system is suppose to prompt the user if they confirm that they would want to include this item.

So I have done the below:
<td height="23"><p align="center"><font face="Verdana" size="1"><INPUT type="checkbox" name="chk" onclick = "return confirmSubmit(<%rstSearch("bAbnormal")%>)" value ="<%=rstSearch("OrderID")"</font></p></td>                        

<script LANGUAGE="JavaScript">
function confirmSubmit(bNorm)
{
if (bNorm==1){
      var agree=confirm("Are you sure you wish to continue?");
      if (agree)
            return true ;
      else
            return false ;
      }
}
</script>


But I wish to add in the part that I will de-select the checkbox if the user click on 'Cancel', and leave the checkbox selected if the user click on 'OK'. Can someone help me with this? Thanks!
0
Comment
Question by:sata
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
in your buttons, try change it like:

<input name="OK" type="button" value="OK" onClick="document.forms[0].chk.checked=true">
<input name="Cancel" type="button" value="Cancel" onClick="document.forms[0].chk.checked=false">

?
0
 
LVL 12

Expert Comment

by:ill
Comment Utility
<td height="23"><p align="center"><font face="Verdana" size="1"><INPUT type="checkbox" name="chk" id="chk" onclick = "return confirmSubmit(<%rstSearch("bAbnormal")%>)" value ="<%=rstSearch("OrderID")"</font></p></td>          
<script type="text/javascript">
function confirmSubmit(bNorm)
{
if (bNorm==1){
     var agree=confirm("Are you sure you wish to continue?");
     if (agree)
          return true ;
     else{
          document.getElementById("chk").checked=false;
          return false ;
          }
     }
}
</script>
0
 
LVL 15

Expert Comment

by:joeposter649
Comment Utility
You should probably also change
<%rstSearch("bAbnormal")%>
to
<%=rstSearch("bAbnormal")%>
0
 
LVL 15

Accepted Solution

by:
joeposter649 earned 50 total points
Comment Utility
You could also pass in "this" so you could call it from any chekcbox.

For example...
<html>
<head>
<script language="javascript" type="text/javascript">
function confirmchk(btn) {
      if (btn.checked == false) {
            if (confirm("are you shure?")){
                  btn.checked = true;
            }
      }
}
</script>
</head>
<body>
<form>
<input type=checkbox onmousedown='return confirmchk(this);' ID="Checkbox1" NAME="Checkbox1">checkbox 1 <br>
<input type=checkbox onmousedown='return confirmchk(this);' ID="Checkbox2" NAME="Checkbox2">checkbox 2 <br>
<input type=checkbox onmousedown='return confirmchk(this);' ID="Checkbox3" NAME="Checkbox3">checkbox 3 <br>
</form>
</body>
</html>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now