Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on 

For Loop In classic ASP VB script

Am using VB scipt in classic asp..
i need a for loop ..which creates  rows with dese details....in dat loop i should iterate with a single row only....i.e here i used three <tr> html tag which created three rows ..but i need one <tr> html tag in for loop so it ll create three <tr>html tage on execution..
<table>
<tr>
                    <td><input type="checkbox" value="5" name="Chk" <%=r1%>/></td>
                    <td>america</td>
                    <td><input type="checkbox" value="5" name="Chk" <%=r1%>/></td>
                    <td>russia</td>
                  </tr>
                  <tr>
                    <td><input type="checkbox" value="6" name="Chk" <%=r2%>/></td>
                    <td>china</td>
                    <td><input type="checkbox" value="6" name="Chk" <%=r2%>/></td>
                    <td> japan</td>
                  </tr>
                  <tr>
                    <td><input type="checkbox" value="7" name="Chk" <%=r3%>/></td>
                    <td>india</td>
                    <td><input type="checkbox" value="7" name="Chk" <%=r3%>/></td>
                    <td>pak</td>
                  </tr>
</table>

Open in new window

VB ScriptASPHTML

Avatar of undefined
Last Comment
Rajar Ahmed
Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

a basic loop to write out 3 rows would be:
<%
 
For Counter = 1 To 3
%>
<tr>
    <td><input type="checkbox" value="5" name="Chk" <%=r1%>/></td>
    <td>america</td>
    <td><input type="checkbox" value="5" name="Chk" <%=r1%>/></td>
    <td>russia</td>
</tr>
 
<%
Next
%>

Open in new window

Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER

hi ..
this repeating america russia three times with txtbox...
but i need every row with those values ..
i mean.....Like this i need,,,,,
(checkbox) america       (checkbox) russia
(checkbox)china     (checkbox) japan
(checkbox)india      (checkbox) pakistan


But the otput was like this....

(checkbox) america       (checkbox) russia

(checkbox) america       (checkbox) russia

(checkbox) america       (checkbox) russia
Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

I wasn't sure exactly what you wanted in the loop, why do you want to use a loop? where are you getting the values <%=r1%> from?

If there's not a datasource I'm not sure you really gain much from coding a loop, it might end up being more work than what you already have.
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER

i need in loop....those countries name...
can it be made using with arrays...??




Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER


 Well, thanks ...I dont any values now i mean ...<%=r1%>,<%=r2%>,<%=r3%> its not neccessary.,
 
Can  u plz form a loop , in such a way to represent like this.....
(checkbox) america  (checkbox) russia
(checkbox)china     (checkbox) japan
(checkbox)india      (checkbox) pakistan

<tr>
    <td><input type="checkbox" value="5" name="Chk" ></td>
    <td></td>
    <td><input type="checkbox" value="5" name="Chk" /></td>
    <td></td>
</tr>


 
Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

Sure I see now:
<table>
 
<%
 
dim countries(2,1)
 
countries(0,0) = "america"
countries(0,1) = "russia"
 
countries(1,0) = "china"
countries(1,1) = "japan"
 
countries(2,0) = "india"
countries(2,1) = "pak"
 
 
 
For counter = 0 to ubound(countries)
 
%>
 
 
 
 
<tr>
    <td><input type="checkbox" value="<%=counter %>" name="Chk" /></td>
    <td><%=countries(counter,0) %></td>
    <td><input type="checkbox" value="<%=counter %>" name="Chk" /></td>
    <td><%=countries(counter,1) %></td>
  </tr>
 
 
 
 
<%
next
%>
 
</table>

Open in new window

Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

If you want to be able to set the value attribute you could do this


dim countries(2,2)

countries(0,0) = "america"
countries(0,1) = "russia"
countries(0,2) = 5

then return the value like this:

value="<%=countries(counter,2) %>"



Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER


Getting this error..
Cannot use parentheses when calling a Sub
<td><input type="checkbox" value="<%=counter,2 %>" name="Chk" /></td>
Response.Write(counter,2)

<table>
 
<%
 
dim countries(2,2)
 
countries(0,0) = "america"
countries(0,1) = "russia"
countries(0,2) = 5
 
countries(1,0) = "china"
countries(1,1) = "japan"
countries(0,2) = 5
 
 
countries(2,0) = "india"
countries(2,1) = "pak"
countries(0,2) = 5
 
 
 
For counter = 0 to ubound(countries)
 
%>
 
 
 
 
 
    <tr>
    <td><input type="checkbox" value="<%=counter,2 %>" name="Chk" /></td>
    <td><%=countries(counter,0) %></td>
    <td><input type="checkbox" value="<%=counter,2 %>" name="Chk" /></td>
    <td><%=countries(counter,1) %></td>
  </tr>
  
 
 
 
 
<%
next
%>
 
</table>

Open in new window

Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

You just missed ou the array name when you called it in the value attribute:

="<%=counter,2 %>"

should be ="<%=countries(counter,2) %>"


Also you need to set the value in the array:


countries(0,0) = "america"
countries(0,1) = "russia"
countries(0,2) = 5
 
countries(1,0) = "china"
countries(1,1) = "japan"
countries(1,2) = 6
 
 
countries(2,0) = "india"
countries(2,1) = "pak"
countries(2,2) = 7

ASKER CERTIFIED SOLUTION
Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER

hi, i ve 2 buttons on that table below .. there was action on clicking on those buttons when i had three rows ... but now i dont find any  kind of action  happpening on clicking that button..
 
 <tr><td>&nbsp;</td>
                     <td><input type="button" name="butt_grp_add" value="Remove" onclick="remgrp(document.frmgrp_<%=cnt%>)"/>  </td>
                     <td>&nbsp;</td>
                     <td><input type="button" name="butt_grp_rem" value="Show" onclick="addgrp(document.frmgrp_<%=cnt%>)"/> <a href="javascript:hidediv(<%=cnt%>)">Close</a></td>
                   </tr>
   

<table>
 
<%
 
dim countries(2,2)
 
countries(0,0) = "america"
countries(0,1) = "russia"
countries(0,2) = 5
 
countries(1,0) = "china"
countries(1,1) = "japan"
countries(1,2) = 6
 
 
countries(2,0) = "india"
countries(2,1) = "pak"
countries(2,2) = 7
 
 
 
For counter = 0 to ubound(countries)
 
%>
 
    <tr>
    <td><input type="checkbox" value="<%=countries(counter,2) %>" name="Chk" /></td>
    <td><%=countries(counter,0) %></td>
    <td><input type="checkbox" value="<%=countries(counter,2) %>" name="Chk" /></td>
    <td><%=countries(counter,1) %></td>
  </tr>
 
 
<%
next
%><tr><td>&nbsp;</td>
                    <td><input type="button" name="butt_grp_add" value="Remove" onclick="remgrp(document.frmgrp_<%=cnt%>)"/>  </td>
                    <td>&nbsp;</td>
                    <td><input type="button" name="butt_grp_rem" value="Show" onclick="addgrp(document.frmgrp_<%=cnt%>)"/> <a href="javascript:hidediv(<%=cnt%>)">Close</a></td>
                  </tr>
 
</table>

Open in new window

Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER

thanks....
Avatar of mrGreen
mrGreen
Flag of United Kingdom of Great Britain and Northern Ireland image

are the buttons working?
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

ASKER

ya....its working......
thanks a lot.....
ASP
ASP

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo