CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2000
    Posts
    12

    Iterating over form fields at client side

    Hi,

    On a webform that I have created I need to be able to loop through a number of textbox values and determine if they are greater than a specified amount, before the form is submitted.

    In the old asp architecture I would do the following:

    <button .......on click='checkdetails(form,form.elements.length)'...>

    this would then call a predefined javascript function that would look something like:

    checkdeatils(form,x)
    {
    if(form.textbox1.value + form.textbox2.value = 33)
    {
    alert('ok your amonut is ok')
    }
    else
    {
    form.submit
    }
    }



    What i need to do is get this same functionality into .net. It looks like this is done through the custom validation control, which I have got to call a javascript function. What I cannot do however is somehow get this function to reference more than one control/form value (i.e. multiple textboxes as above).

    Can this be done??

    Many Thanks

    Simon

  2. #2
    Join Date
    Jul 2002
    Posts
    62
    You need to look into the asp:RangeValidatorControl

    Try

    asp:RangeValidator id="RangeValidator1"
    runat="server"
    errormessage="This value is too low."
    controltovalidate="tbValue"
    Type=integer
    MinimumValue="10"

  3. #3
    Join Date
    Nov 2000
    Posts
    12
    Hi,

    yeh thanks, I already use the range validator fine for a single control, what I need to do however is comapre the values of several controls (12 to be exact), and need some way of referencing multiple controls in javascript/vbscript. The ranage validator and the other validators ask u to specify a single control, i.e. the 'control to validate', I almost need a :
    'multiple controls to validate'.

    I could do this in the old style of asp by passing the form and its values to a javasrcipt function, and then do something like:

    if(form.textbox1.value + form.textbox2.value = 33)
    {
    ......
    }

    but cannot see how to do this in .net, surely this can be done though???

    Many Thanks

    Simon

  4. #4
    Join Date
    Nov 2000
    Posts
    12

    Re : ok now

    Hi,

    In the end I used the html buttons in .net and not the web forms controls, as i managed to get the onclick=function1() within the button <input tag.

    From there i used the standard document.form1.textbox1.value way.

    I still don't know how to get this onclick to work from within the web forms buttons, have used the html control instead.

    Simon

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

Featured