Solved

Select/Deselect checkbox using javascript

Posted on 2004-09-30
4
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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