Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2004, 06:35 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default How to put "check all" checkbox

I have a column of checkboxes in the ASP response page. How do I put the "check all" checkbox? The Javascript below was a "submit" button originally.

Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
  field[i].checked = true ;
}

//  End -->
</script>
And now the Body:
Code:
<input type="checkbox" name="CheckAll" value="Check All" onClick="this.value=checkall(this.form.list);">
 
Old September 10th, 2004, 06:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Make a form and a JavaScript function called when you click a button like this:

<form id='d' [other attributes]>
<input type='checkbox' name='ch1'/>
<input type='checkbox' name='ch2'/>
<input type='checkbox' name='ch3'/>
<input type='button' onclick='checkAll(document.forms.d)' value='check all'/>
</form>
<script type='text/javascript'>
function checkAll(form)
{
    for(var i = 0; i < form.length; i++)
    {
        if(form[i].type = 'checkbox')form[i].checked = 'checked';
    }
}
</script>

HTH,

-Snib <><
http://www.snibworks.com/
 
Old September 10th, 2004, 07:07 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok. SO I changed the button into a checkbox since that's what I needed. The checkbox checks all as I wanted. But I can't uncheck it!

Code:
<body>
<form id='d' [other attributes]>
<input type='checkbox' name='ch1'/>
<input type='checkbox' name='ch2'/>
<input type='checkbox' name='ch3'/>
<input type='checkbox' onclick='checkAll(document.forms.d)' value='check all'/>
</form>
<script type='text/javascript'>
function checkAll(form)
{
    for(var i = 0; i < form.length; i++)
    {
        if(form[i].type = 'checkbox')form[i].checked = 'checked';
    }
}
</script>
</body>
 
Old September 10th, 2004, 07:13 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this instead:

Code:
<body>
<form id='d' [other attributes]>
<input type='checkbox' name='ch1'/>
<input type='checkbox' name='ch2'/>
<input type='checkbox' name='ch3'/>
<input type='checkbox' onclick='checkAll(document.forms.d,this)'/>
</form>
<script type='text/javascript'>
function checkAll(form,cbox)
{
    for(var i = 0; i < form.length; i++)
    {
        if(form[i].type=='checkbox' && cbox.checked=='checked')form[i].checked = '';
        else if(form[i].type=='checkbox' && cbox.checked=='')form[i].checked = 'checked';
    }
}
</script>
</body>
-Snib <><
http://www.snibworks.com/
 
Old September 10th, 2004, 07:15 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

question 2 since your last reply: what if the column checkboxes represent the ASP response page's result of a query, where each checkbox represents an "id" from the table?
How would the names and values be?

 
Old September 10th, 2004, 07:20 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

WHat's happenning is that when I check the last checkbox, that one alone is checked. But when I uncheck, it doesn't uncheck. Instead it checks all the rest. But never unchecks.

 
Old September 10th, 2004, 07:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Here's a modified version of the code, let me know if it helps:

<body>
<form id='d' [other attributes]>
<input type='checkbox' name='ch1'/>
<input type='checkbox' name='ch2'/>
<input type='checkbox' name='ch3'/>
<input type='checkbox' onclick='checkAll(document.forms.d,this)'/>
</form>
<script type='text/javascript'>
function checkAll(form,cbox)
{
var ct;
if(cbox.checked == true)ct = false;
else if(cbox.checked == false)ct = true;
    for(var i = 0; i < form.length; i++)
    {
        if(form[i].type=='checkbox')form[i].checked = ct;
    }
}
</script>
</body>

-Snib <><
http://www.snibworks.com/
 
Old September 10th, 2004, 07:29 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok now, pressing the last one doesn't check. BUT when I select the first 3 and THEN check the 4th it unchecks all.

 
Old September 10th, 2004, 07:33 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok. There was a confusion in the true and false. Thanks.

 
Old September 10th, 2004, 07:47 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

I tried in the page. But it says "length is null or not an object"

Code:
    <HTML>
    <HEAD><TITLE>Result Page</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
function checkAll(form,cbox)
{
var ct;
if(cbox.checked == true)ct = true;
else if(cbox.checked == false)ct = false;
    for(var i = 0; i < form.[u]length</u>; i++)
    {
        if(form[i].type=='checkbox')form[i].checked = ct;
    }
}
</SCRIPT>
</HEAD>
<BODY>

<table border="1" cellspacing="0" cellpadding="0" width="732" style="width:549.0pt;
 border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 0in 0in 0in">
 <tr style="height:12.75pt">
 <th bgcolor="#800000">
 <form align="center" method="get" action="my_edit_links_rec_action.asp" id=form1 name=form1>Select<br>
 <select size="1" name="choices" id="choices">
        <option SELECTED VALUE="">None</option> 
        <option VALUE="001">Delete</option>
        <option VALUE="002">Email to:</option>
        <option VALUE="003">Print</option>
        <option VALUE="004">Save in:</option>
 </select><input type="submit" value="OK" name=submit1><br>
<input type='checkbox' onclick='checkAll(document.forms.d,this)' value='check all'/>
 Select All</th>
 <th bgcolor="#800000">Book Title</th>
 <th bgcolor="#800000">Book #/<br>Book Spoke</th>
 <th bgcolor="#800000">Chapter #/<br>Chapter Spoke</th>
 <th bgcolor="#800000">Verse #/<br>Verse Spoke</th>
 <th bgcolor="#800000">Text</th>
  </tr>
  <td width="135" nowrap rowspan="2" style="width:101.25pt;border:solid windowtext .5pt;
  border-right:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;height:
  8.0pt">

        <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"
        S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
        <p> <input type="checkbox" name="CheckAll"></p>
      </form>
      <p>&nbsp;
    </td>
    <td width="135" nowrap rowspan="2" style="width:101.25pt;border:solid windowtext .5pt;
  border-right:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;height:
  8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("book_title")%><o:p>
      <td width="149" nowrap style="width:111.75pt;border-top:solid windowtext .5pt;
  border-left:none;border-bottom:solid windowtext .75pt;border-right:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("book")%><o:p>
      </o:p>
      </span></p>
    </td>
    <td width="164" nowrap style="width:123.0pt;border-top:solid windowtext .5pt;
  border-left:none;border-bottom:solid windowtext .75pt;border-right:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("chapter")%><o:p>
      </o:p>
      </span></p>
    </td>
       <td width="151" nowrap style="width:113.25pt;border-top:solid windowtext .5pt;
  border-left:none;border-bottom:solid windowtext .75pt;border-right:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("verse")%><o:p>
      </o:p>
      </span></p>
    </td>
    <td width="245" nowrap rowspan="2" valign="top" style="mso-border-left-alt: solid windowtext .75pt; height: 12.75pt; border-left-style: none; border-left-width: medium; border-right: .5pt solid windowtext; border-top: .5pt solid windowtext; border-bottom: .5pt solid windowtext; padding-left: .75pt; padding-right: .75pt; padding-top: .75pt; padding-bottom: 0in">
      <p class="MsoNormal"><span style="font-size:10.0pt;font-family:Verdana"><b><%=rs("book_title")%>&nbsp;&nbsp;<%=rs("chap")%>:<%=rs("vers")%></b><br><%=rs("text_data")%><o:p>
      </o:p>
      </span></p>
    </td>
  </tr>
  <tr style="height:8.0pt">
    <td nowrap style="border-top:none;border-left:none;border-bottom:solid windowtext .5pt;
  border-right:solid windowtext .75pt;mso-border-top-alt:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("book_spoke")%><o:p>
      </o:p>
      </span></p>
    </td>
    <td nowrap style="border-top:none;border-left:none;border-bottom:solid windowtext .5pt;
  border-right:solid windowtext .75pt;mso-border-top-alt:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("chapter_spoke")%><o:p>
      </o:p>
      </span></p>
    </td>
       <td nowrap style="border-top:none;border-left:none;border-bottom:solid windowtext .5pt;
  border-right:solid windowtext .75pt;mso-border-top-alt:solid windowtext .75pt;
  mso-border-left-alt:solid windowtext .75pt;padding:.75pt .75pt 0in .75pt;
  height:8.0pt">
      <p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:Verdana"><%=rs("verse_spoke")%><o:p>
      </o:p>
      </span></p>
    </td>
  </tr>
  </table>

</BODY>
</HTML>





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Print the row of datagrid with checkbox with check niks_crasher VS.NET 2002/2003 0 September 2nd, 2006 03:45 AM
Enable Radio when check on Checkbox... rupen Javascript How-To 2 June 28th, 2006 04:44 AM
how delete row in datagrid which check checkbox ashish2001mca Forum and Wrox.com Feedback 1 September 18th, 2005 03:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.