Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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
  #1 (permalink)  
Old August 4th, 2005, 10:54 AM
Registered User
 
Join Date: Aug 2005
Location: Fort Walton Beach, FL, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing Checkbox Names

I'm setting up a Javascript that checks or unchecks all. The script I have looks for all the form elements with the same name. So I want my checkboxes to end up in html like this:

<input id="chkBox1" type="checkbox" name="chkBoxes" onclick="checkOrUncheck('chkBox1')" />
<input id="chkBox2" type="checkbox" name="chkBoxes" onclick="checkOrUncheck('chkBox2')" />
<input id="chkBox3" type="checkbox" name="chkBoxes" onclick="checkOrUncheck('chkBox3')" />

However, I keep getting:

<input id="chkBox1" type="checkbox" name="chkBox1" onclick="checkOrUncheck('chkBox1')" />
<input id="chkBox2" type="checkbox" name="chkBox2" onclick="checkOrUncheck('chkBox2')" />
<input id="chkBox3" type="checkbox" name="chkBox3" onclick="checkOrUncheck('chkBox3')" />

The name attribute is the same as the id. In the code behind I've added

chkBox.Attribute["name"] = "chkboxes";

which produced:

<SPAN Name="chkboxes">
<input id="chkBox1" type="checkbox" name="chkBox1" onclick="checkOrUncheck('chkBox1')" /></SPAN>
<input id="chkBox2" type="checkbox" name="chkBox2" onclick="checkOrUncheck('chkBox2')" /></SPAN>
<input id="chkBox3" type="checkbox" name="chkBox3" onclick="checkOrUncheck('chkBox3')" /></SPAN>

I tried:

chkBox.Attribute["name"].Replace(chkBox.ID, "chkBoxes);

which didn't render the page at all.

How do I get the name attribute to change?

PRD
  #2 (permalink)  
Old August 4th, 2005, 06:03 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Why would you want the id and name different? these should be the same, shouldnt they?


Anyhow if I want to produce checkboxes dynamicly that have unique names I do the following (this assumes you have a record set called rs):
<%
dim count
count = 1
if not rs.Eof then
   do until rs.Eof %>
      <input type="checkbox" name="chkBox<%= count %>" onclick="checkOrUncheck('chkBox<%= count %>')"
<% rs.moveNext
      count = count + 1
   loop
else
   'no records
end if
%>


Wind is your friend
Matt


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning ASP 3.0: changing text field to checkbox AlanM Classic ASP Basics 0 July 1st, 2007 03:36 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
To Many Names bachuss SQL Language 0 January 18th, 2006 12:40 PM
changing Text source file names rjjhome SQL Server DTS 1 August 18th, 2004 02:27 PM





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