Solved

Select/Deselect checkbox using javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

19 Experts available now in Live!

Get 1:1 Help Now