PDA

Click to See Complete Forum and Search --> : Question about naming textboxes!!


msuryadarma
Oct 4th, 2000, 03:30 PM
Hi all, sorry for posting so many questions.

Here it is.

I have a For loop that makes textboxes in a form based on user input. If user inputs Num = 5, 5 textboxes will come out and their NAMEs are txtGuest_1, txtGuest_2, etc. This works fine. This is being done in the server-side script.

Now, I want user to put numbers into those textboxes, and add the total value of them all by pressing a button (cmdGo).

In the client-side script:

-------------
Sub cmdGo_OnClick

Dim Tot
Tot = 0

For counter = 1 to Num
Tot = Tot + Document.frmBoxes.txtGuest_counter.Value
Next

Msgbox Tot
---------------

This code does NOT work. It says Object doesn't support this property or method Document.frmBoxes.txtGuest_counter.

So how can I do this? I need to call each boxes by their names, and the names depend on the user input.

By the way, there is no other problem in my files. If I simply replace the For Loop with
MsgBox Document.frmBoxes.txtGuest_1.Value for example, it will show whatever number I put in textbox 1.

THANK YOU SO MUCH!!! Please help...

Martin

monte96
Oct 4th, 2000, 04:01 PM
Give all the text boxes the same name and refer to them by index.

msuryadarma
Oct 5th, 2000, 08:50 AM
Monte, thanks for the reply.

I tried doing that, but it doesn't seem to work. For example, I name them txtGuestNum(1), txtGuestNum(2). And I try to refer them by txtGuestNum(counter). It doesn't work. I get the same errors. Or am I doing it wrong?

This is how I create the boxes in server-side script:
------------------------------
For Counter = 1 to GuestNum

Response.Write "input TYPE=text NAME=txtGuestEat(" & Counter & ") SIZE=15>"

Next
------------------------------

Then when I tried to refer it back with txtGuestEat(counter), it pukes. Am I doing it wrong?

Thanks a lot!!

monte96
Oct 5th, 2000, 10:06 AM
No...

don't give them names like txtGuestNum(1)..

give them all the name 'txtGuestNum'

They will be enumerated in the form collection and you WILL be able to access them as Request.Form("txtGuestNum")(1), Request.Form("txtGuestNum")(2), etc..


'Assuming Server side script here after the submit button has been clicked
Dim intLoop
Dim intCount

intCount = 0
For intLoop = 1 to Request.Form("txtGuestNum").Count
intCount = intCount + Request.Form("txtGuestNum")(intLoop)
Next

Response.Write "Total Number=" & intCount & "<BR>"


The syntax is a little different on the client side but the concept is pretty much the same (no Request object available on the client side but you should still be able to loop through them)

msuryadarma
Oct 5th, 2000, 10:28 AM
:D

Monte, you DA MAN!!!

Thanks a lot dude, it works perfectly now!

You're definitely a valuable member of this community, thanks again.

Martin

monte96
Oct 5th, 2000, 02:33 PM
No problem dude and btw- no need to apologize for too many questions... ask away.. :c)