Results 1 to 3 of 3

Thread: [RESOLVED] JavaScript + Required fields validators

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Resolved [RESOLVED] JavaScript + Required fields validators

    Hi all,

    I have this code:
    VB Code:
    1. Dim sb As New System.Text.StringBuilder
    2.                         'sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
    3.                         'sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
    4.                         sb.Append("var answer = confirm('Update client?'); ")
    5.                         sb.Append("if (answer) { ")
    6.                         sb.Append(Me.Page.GetPostBackEventReference(Me.btnCopyAddress))
    7.                         sb.Append("; ")
    8.  
    9.                         For i = 1 To collClient.Count
    10.                             sStr = CType(collClient(i), ClientFields)
    11.                             If Left(sStr.sField, 1) = "s" Then
    12.                                 sb.Append("document.forms(0)." & sStr.sField & ".value = """ & sStr.sValue & """;")
    13.                             End If
    14.                         Next i
    15.  
    16.                         sb.Append("}")
    17.                         'sb.Append("this.image=""images\editbutton.jpg""; }")
    18.                         sb.Append(" else {")
    19.                         sb.Append(" return false; }")
    20.                         btnCopyAddress.Attributes.Add("onclick", sb.ToString())

    This code works when all required fields are filled. If not, the code won't change any of the fields, could there be a reason why?

    I make it stranger: this code works when all required fields are filled, EXCEPT the fields that are filled through this code... Thus, if the required fields that are changed by this code are not filled, and all other required fields are, it works. But, if one field that is required and NOT changed by this code is not filled, the whole code doesn't work...

    Is there anyone who could tell me how to work around the required fields? Thanx in advance...

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: JavaScript + Required fields validators

    Perhaps because the text being created with javascript exists only on the client side, so your server side update method has no clue that it exists.

  3. #3

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: JavaScript + Required fields validators

    Quote Originally Posted by wild_bill
    Perhaps because the text being created with javascript exists only on the client side, so your server side update method has no clue that it exists.
    Nope, isn't true . Have found problem:

    if I remove these two rules:
    VB Code:
    1. sb.Append(Me.Page.GetPostBackEventReference(Me.btnCopyAddress))
    2. sb.Append("; ")
    It doesn't post back, but loops locally through the fields in the browser and updates the ones needed .

    Anyway, thanx for you response...

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