Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 12th, 2006, 11:04 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic check boxes and select lists

Hello,

I am trying to create an ASP page that has both dynamic checkboxes and dynamic Select lists which pulls its data from a database table. However, I also include a JavaScript function to disable the Select list by default and only enable the Select list if the Checkbox is clicked.

I am having the following problem: if i have 3 checkboxes with 3 select lists, when I click the first check box, it enables the first select list, which is what it's supposed to do. But when I click the second check box, it disables the first select list. So how can I get the second check box to enable the second select list, and so on?

Here is the code that i am trying to use:


Code:
<script language="Javascript">
<!--
function toggleStatus(cb, selID)
{    
    var sel = document.getElementById(selID);
    // This line disables the select when the checkbox is ON (ticked). 
    sel.disabled = !cb.checked;
}
//-->            
</script>
<% 
'Write the values
do while not rs.eof
%>
<form name="select_treatment" action="confirm_sale.asp" method="get" >
<td width="1000">
<input type="checkbox" name="<%=rs.Fields(0).Value%>" id="checkbox1" value="<%= rs("treatmentID")%>" onClick="toggleStatus(this,'select1' "></td>
<td width="1000" class="body"><%= rs("treatmentName") %></td>
<td width="1000" class="body"><%= rs("treatmentDescription") %></td>
<td width="1000" class="body">€<%= rs("treatmentPrice") %></td>
<td width="1000" class="body"><%= rs("treatmentDuration") %></td>
<td width="1000" class="body">

I think the Select Name and ID is where the problem occurs    
<select name="select1" id="select1" disabled>

<%
'while not the end of our staff member record set
do while not rs2.EOF 
%>
<option value="<%Response.Write rs2("staffID")%>"> <%Response.Write rs2("firstName")%></option>
<%
' Move to the next record
rs2.MoveNext
' Loop 
Loop

' move back to the first record
rs2.MoveFirst
%>
</td>
</tr>

<% 
rs.movenext
loop 
%>
</select>
Please help as this is really frustrating me!

Reply With Quote
  #2 (permalink)  
Old March 17th, 2006, 04:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii bsheridan!!
Hope this will help you,
<script>
function toggleStatus(id)
{
var selID;
for(i=1;i<=3;i++)
{
selID="select"+i
    var sel = document.getElementById(selID);
    sel.disabled =true

}

  selID="select"+id
    var sel = document.getElementById(selID);
    sel.disabled =false;

}

</script>

<input type=checkbox onclick="toggleStatus(1)"><select id="select1">
<option>1</option>
<option>11</option>
<option>111</option>
<option>11111</option>
</select>
<br><input type=checkbox onclick="toggleStatus(2)"><select id="select2">
<option>1</option>
<option>11</option>
<option>111</option>
<option>11111</option>
</select>
<br><input type=checkbox onclick="toggleStatus(3)">
<select id="select3">
<option>1</option>
<option>11</option>
<option>111</option>
<option>11111</option>
</select>

Note:- since you want to toggle checkbox and select box,
      you can use radio button ,since for checkbox you need to unchecked previous selected checkbox.


Cheers :)

vinod
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with dynamic drop down lists MarkGT Classic ASP Basics 3 April 29th, 2008 06:05 PM
Dynamic checkbox and radiobutton lists Ric_H C# 1 April 5th, 2006 05:04 AM
Dynamic check boxes writing to database..help!! cincinnaticj7 Classic ASP Databases 0 January 25th, 2005 09:47 AM
Help - Dynamic Pop-down lists phpcoder1 PHP How-To 0 November 8th, 2004 11:02 AM
Getting value of Dynamic Check boxes kathryne Classic ASP Databases 3 March 19th, 2004 04:44 AM



All times are GMT -4. The time now is 04:41 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.