Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
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
 
Old May 17th, 2005, 03:38 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I add a variable to the name of a textbox?

Hi there

I’m currently working on quite a complicated project (i.e. it’s all new to me!!) and have a few coding issues that I’ll need to ask you lovely people out there for help on!

I’m working on a ‘Product Returns’ section, so if people want to return items that are damaged/faulty etc, they can go online and enter in all the necessary information.

All the information stored on our system is passed through to my asp page as one long string, with a } separating each line of code, and a | separating each item on each line. This is all fine.

I then have 2 variables, counterx (the line number) and countery (the counter for each item) which allows me to put all the information neatly into a table

e.g. }Jane Bloggs|Necklace|20.00|1|0|}Jane Bloggs|Bracelet|15.00|1|0|}

gives me:

Code:
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>CUSTOMER NAME </td>
    <td>PRODUCT DESCRIPTION </td>
    <td>PRICE</td>
    <td>SHIPPED</td>
    <td>RETURN QTY </td>
  </tr>
  <tr>
    <td> Jane Bloggs </td>
    <td>Necklace</td>
    <td>20.00</td>
    <td>1</td>
    <td>0</td>
  </tr>
  <tr>
    <td> Jane Bloggs </td>
    <td>Bracelet</td>
    <td>15.00</td>
    <td>1</td>
    <td>0</td>
  </tr>
</table>
so on the first line, counterx=0 and on the second line, counterx=1 (and so on for the number of lines I have). And taking line 1, countery=0 would be Jane Bloggs, countery=1 would be Necklace and so on.

So, my first little problem I need to overcome is this…

I’ve managed to swap the Return Qty value that’s currently shown as 0 with a text box for each line. This is because the user will need to enter in their own value.

So, in my code I have the following line
<% Response.write "<input name='rquan' type='text' id='rquan' value='0' size='3' tabindex='1'/>" %>

This writes out the text box fine BUT on every line, this text box is called the same name and I need it to be a unique name, so I thought I’d add the value of counterx to the end of the name so that each one is unique, and corresponds to the correct line.

e.g. On line 1, where counterx=0 I’d like the text box to be called rquan0. On line 2, where counterx=1 I’d like the text box to be called rquan1 etc

I know I need to attach &counterx to the name, somehow BUT I can’t seem to get this to work – any ideas how to solve my first problem (more questions to follow when I get stuck again!!)

Thanks in advance

Lucy

 
Old May 17th, 2005, 04:22 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Lucy,

Try...
[code]
<% Response.write "<input name='rquan" & counterx & "' type='text' id='rquan" & counterx & "' value='0' size='3' tabindex='1'/>" %>
[code]
HTH,

Chris

 
Old May 17th, 2005, 04:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try either this (which is easy on the eye):
sInputCtl = "<input name='rquan%ID%' type='text' id='rquan%ID%' value='0' size='3' tabindex='1'/>"
Response.write Replace(sInputCtl, "%ID%", CStr(counterx))

or this (which is messy but does the same job):
Response.write "<input name='rquan" & counterx & "' type='text' id='rquan" & counterx & "' value='0' size='3' tabindex='1'/>"

BTW you shouldn't write the same tabindex for each control...

hth
Phil
 
Old September 15th, 2009, 12:42 AM
Registered User
 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I try it but some unknown error is occur. If you have another suggestion, please give us.
 
Old September 15th, 2009, 06:48 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Show your *FULL CODE* for at least that part of the page.

Incidentally, you should *NOT* use 'xxxx' in HTML any more. It should always be "...". And since doing the via Response.Write is messy, I *STRONGLY* suggest *NOT* using Response.Write!
Code:
...
' exit from ASP code
%>
<input name="rquan<%=counterx%>" type="text" value="0" size="3" tabindex="1" />
<%
' back into ASP
...
Do *NOT* add an ID to form fields. It's pointless. Only the name is important. Why code more than is needed?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add textbox in cs file khorshid_sh ASP.NET 1.0 and 1.1 Basics 2 April 30th, 2008 02:37 PM
Add new record to databased based on textbox input CarolMorgan Classic ASP Professional 2 January 10th, 2005 01:45 PM
How to add two variable with Decimal values sa_moizatyahoo ASP.NET 1.0 and 1.1 Basics 1 April 3rd, 2004 06:17 AM
add multiple list to textbox stoneman Access 1 November 3rd, 2003 01:10 PM





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