Link to home
Start Free TrialLog in
Avatar of calvinfoo
calvinfoo

asked on

Client side VBScript: track numbers of input fields as in <input name="userID"/>

Hi,

I have multiple <input type="text" name="userID"> on client side, but I have no idea how many it will be before it submits (as user can dynamically click on "add"/"remove" any of the rows).

Question and problem
1. I need to do some clientside validation before submit back to server.  Therefore I need to know how many userIDs were created.  and the problem is when only ONE userID, it will be as text format; if MORE THAN ONE userID created, it will become an array format.  Without knowing the numbers of userID, I cannot determine I should loop UserID as in array for validation or just get the UserID as in single text.

Please advice, thank you.

p/s: currently I put a hidden field as <input type="hidden" name="counter" value="1">
whenever user click on Add, it will +1, whenever user click on Delete, it will -1.  I think this way is pretty stupid, and I hope this is not the way and the only way of doing it.

ASKER CERTIFIED SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mensuck
mensuck

Just use 'for each' in your server side VBScript, it will handle both single element inputs or array element type inputs if the 'form' element is a array!

<script language="VBScript" runat="Server">

      dim opt

      if ( request.form ( "userID" ) <> "" ) then

            for each opt in request.form ( "userID" )

                  ' validation function call or validation goes here, example just shows the form data

                  response.write ( opt & "<br />" )

            next

      end if

</script>

ms!
mensuck,

Since the title of the question is "Client side ..." and the question states "1. I need to do some clientside validation before submit back to server" it seems your suggestion doesn't really address the topic of this question.

Regards,
Rod