Results 1 to 6 of 6

Thread: Question about naming textboxes!!

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    48

    Question

    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

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Give all the text boxes the same name and refer to them by index.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    48

    Can you elaborate?

    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!!


  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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..

    Code:
    '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)
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    48

    Thumbs up FINALLY!!



    Monte, you DA MAN!!!

    Thanks a lot dude, it works perfectly now!

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

    Martin

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    No problem dude and btw- no need to apologize for too many questions... ask away.. :c)
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width