?
Solved

Select/Deselect checkbox using javascript

Posted on 2004-09-30
4
Medium Priority
?
808 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 53

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 200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 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