Current location: Hot Scripts Forums » Programming Languages » ASP » Dynamic form checkboxes (ASP)


Dynamic form checkboxes (ASP)

Reply
  #1 (permalink)  
Old 08-04-03, 12:44 AM
Claralu Claralu is offline
New Member
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Dynamic form checkboxes (ASP)

I`m trying to generate a form with rows from a database and a checkbox, so that when the user checks a checkbox the program executes a SQL statement with all the rows that are checked.

I`m trying the following code to generate the checkboxes.

<% dim i
i=1
while not tabla.EOF %>
<%dim tot1,totval
totval=int(tabla.RecordCount)
tot1=0
%>
<tr>
<td> <% =tabla.Fields("codigo")%> </td>
<td> <% =tabla.Fields("titulo")%> </td>
<td><input type="checkbox" name="cb"&<%= i %> value=tabla.Fields("codigo")>

</td>
</tr>
<% i=i+1
tabla.MoveNext
wend
%>

Then on the asp page that receives the form submit, I`m trying to access the value of the rows with cb&i name to perform the SQL statement with those rows, but I don`t get any results.

I`m new to ASP, please help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-04-03, 04:16 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Well, for one, this line is has a few problems.

Code:
<input type="checkbox" name="cb"&<%= i %> value=tabla.Fields("codigo")>
when this renders to the browser it will look like this:

Code:
<input type="checkbox" name="cb"&1 value=>
<input type="checkbox" name="cb"&2 value=>
<input type="checkbox" name="cb"&3 value=>
...etc
So, basically, you're not naming your checkboxes "cb&NUMBER". You are naming them all "cb" but with some random characters between properties.

You are also trying to set ASP server-side code as the value for the checkbox. You need to put the tabla.Fields("codigo") call between the ASP brackets.

If you want to name all of your boxes "cb", then that's fine. You can just loop through the collection and figure out all of the values.

If you are trying to include that number in the name, then you would want to do something like:

Code:
<input type="checkbox" name="cb&<%= i %>" value="<%=tabla.Fields("codigo") %>">
Each of your checkboxes will then be named "cb&1", cb&2", cb&3" and so on. If you don't want the ampersand in there, then just take it out. Your checked checkboxes will also have a value now.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-06-03, 04:28 PM
BuildHome BuildHome is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Israel
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
You also need to add +1 to variable I, like that:

Code:
<%
i=1
while not tabla.EOF
i = i+1
%>
...
So you will get:
1
2
3
4
.....

Otherwise your variable will be always 1...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-06-03, 04:37 PM
MadDog MadDog is offline
Code Master
 
Join Date: Aug 2003
Posts: 935
Thanks: 0
Thanked 0 Times in 0 Posts
This would be what you want to use for the code,

Code:
<%
Dim i
Dim tot1
Dim totval

i = 1

Do WHILE NOT tabla.EOF
	totval = int(tabla.RecordCount)
	tot1 = 0
%>
 <tr> 
  <td><% = tabla("codigo") %></td>
  <td><% = tabla("titulo") %></td>
  <td><input type="checkbox" name="cb&<% = i %>" value="<% = tabla("codigo") %>"></td>
 </tr>
<%
	i = i + 1
tabla.MoveNext
Loop
%>
__________________
Drew Gauderman
ASP - MSSQL Coder / Buisness Owner / Coder for Hire!
MSN-ICQ-AIM-YIM in Profile

http://www.iportalx.net an easy ASP portal system.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkboxes on form = mailto recipient. Bojon PHP 4 12-21-04 07:07 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM
asp: URGENT! need to change code to create new form per id seala ASP 2 09-09-03 10:54 PM
asp: validating checkboxes in groups by groupid seala ASP 0 09-08-03 02:36 PM
asp: checkboxes & multi-page form seala ASP 0 09-02-03 02:58 PM


All times are GMT -5. The time now is 01:04 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.