Solved

Select/Deselect checkbox using javascript

Posted on 2004-09-30
4
803 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 50

Expert Comment

by:Ryan Chong
ID: 12188401
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
ID: 12188876
<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
ID: 12200282
You should probably also change
<%rstSearch("bAbnormal")%>
to
<%=rstSearch("bAbnormal")%>
0
 
LVL 15

Accepted Solution

by:
joeposter649 earned 50 total points
ID: 12200565
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

832 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