[RESOLVED] JavaScript + Required fields validators
Hi all,
I have this code:
VB Code:
Dim sb As New System.Text.StringBuilder
'sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
'sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
sb.Append("var answer = confirm('Update client?'); ")
sb.Append("if (answer) { ")
sb.Append(Me.Page.GetPostBackEventReference(Me.btnCopyAddress))
sb.Append("; ")
For i = 1 To collClient.Count
sStr = CType(collClient(i), ClientFields)
If Left(sStr.sField, 1) = "s" Then
sb.Append("document.forms(0)." & sStr.sField & ".value = """ & sStr.sValue & """;")
End If
Next i
sb.Append("}")
'sb.Append("this.image=""images\editbutton.jpg""; }")
sb.Append(" else {")
sb.Append(" return false; }")
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...
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.
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:
sb.Append(Me.Page.GetPostBackEventReference(Me.btnCopyAddress))
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...