Repeating form field validation

Results 1 to 3 of 3

Thread: Repeating form field validation

  1. #1
    Join Date
    Dec 1969

    Default Repeating form field validation

    Hi<BR><BR>I&#039m working on an intranet expense claims application that has 15 details rows to allow a user to add details of claims. Each row has a type field (field names type1 to type15) and an amount field (field names amount1 to amount15). In the validation routine a check is performed on the type field - if its a certain type then a check needs to be performed on the amount to see if it exceeds an allowed limit. The only way I can find of validating at the moment is to refer to the fields as theform.amount1.value etc ... obviously I have to repeat this 15 times. Ideally I&#039d like to use a loop but I can&#039t find anyway to reference the field names other than amount1, amount2 etc .. I tried creating a loop and referencing the fields by using theform.amount&intloop.value etc but obviously this wont work - I&#039ve given an example below:<BR><BR>In my form I create the fields by using a loop for example -<BR><BR>For intloop = 1 to 15<BR><BR>response.write INPUT name = type" & intloop <BR>response.write INPUT name = amount" & intloop<BR><BR>next<BR><BR>I then need to validate the contents of the amount against the type eg<BR><BR>if the form.type1.value = "Travel" then<BR>if the form.amount1.value &#062; 20 then<BR>msgbox("The limit for travel is £20")<BR>end if<BR>end if<BR><BR>Obviously I need to repeat this for each row on the form - and there are 15 rows. The actual validation is much more complex than I&#039ve shown above and I don&#039t want to be repeating the same block of code 15 times, just substituting the number each time eg type1 and amount1, type2 and amount2.<BR><BR>Has anyone any suggestions ?<BR><BR>Thanks, Nic<BR>

  2. #2
    paul_merton @ Guest

    Default RE: Repeating form field validation

    If you are going to be using server-side validation and if you are using IIS5, then you should be able to accomplish your goal by using the &#039Execute&#039 fuction.<BR><BR>E.g. the following...<BR><BR>&#060;%<BR>x = 2<BR>Execute "variablename" & x & " = 12"<BR>%&#062;<BR><BR> identical to...<BR><BR>&#060;%<BR>variablename2 = 12<BR>%&#062;<BR><BR>If you are not using IIS5, then another alternative method of server-side validation can be done by setting all of the field names to the same (i.e. just "type" and "amount").<BR>You can then refer to them by array index (1-15) for example Request("type")(1) returns the first type field and Request("type")(15) returns the last type field.<BR><BR>I realise that you&#039re probably looking for some sort of client-side validation, but ultimately a bit of server-side validation provides better robustness.<BR><BR>Anyway, I hope that gives you some ideas,<BR>Paul.

  3. #3
    Join Date
    Dec 1969

    Default RE: Repeating form field validation

    I tend to be a fan of client-side validation. Client-side validation tends to provide a &#039quicker&#039 validation response because there is no &#039posting&#039 of the form, thus eliminating connection concerns.<BR><BR>It may seem tedious, but why not load the potential values from the fields into arrays? something like:<BR><BR>dim name(15), limit(15), type(15), amount(15)<BR> -- you could even dynamically size these values if you read <BR> them from a database.<BR><BR> name(j) = Travel<BR> limit(j) = 20<BR><BR>then test your form field values against the array that was just created:<BR><BR> if form.type(i).value = name(j) then<BR> if form.amount(i).value &#062; limit(j) then<BR> msgbox (name(j) & " limit is " & limit(j) & ".")<BR> end if<BR> end if<BR><BR><BR>This shell should provide an idea and may be worth looking at for your situation.

Posting Permissions

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