Friday 15 January 2010

javascript - Using Blur and Submit events on the same form -


I am still confused about it now about a week started learning JQuery and I have it: / P>

  var IsValidUserName = false; $ (Document) .ready (function () {$ ('# txtUserName'). Blur (function () {if ($ ('# txtUserName'). Val (). Match (isNumberLetter) & amp; amp; ($ ('#txtUserName'). Val () Length = (8)) {$ ('# User Name Error') RemoveClass ("Error"). AddClass ("default"); $ ('# txtUserName' RemoveClass ("Edit"); $ ('# txtUserName + label'). RemoveError ("id", "lblUserName"); IsValidUserName = true;} and {$ ('# user name entry'). AddClass "" "$" ("#", "Error"); $ ('# txtUserName'). AddClass ("Warning"); $ ('# txtUserName + label'). Attr ("id", "LblUserName");}}};}); Let's say I have another function, say   first name  :  

How do I do this? Will I call on the incident? This code works as I need it when the user leaves the field. Not sure how I can call this code and if the data entered is invalid, I can also use the above variable to stop submitting.

If the user clicks the submit button and pauses the submission, if IsValidUserName is the variable false .

Some things just need a little push.

Thanks, my friends.

Boy

You can always remove it in the function instead of an anonymous function And the passage can pass the object that you want to see, you will get the added advantage of reusing it for other elements.

  function is valid (ele) {var valid; If (ele.val () match (isNumberLetter) & amp; Amp; (Ele.val (.) Length & gt; = 8)) {Valid = true; // update user here} other {legitimate = false; // update user here} return valid; } $ (Function () {$ ('first name'). Blur (function () {valid ($ (this))}} $ $ ('# last name'). Blur (function () {valid ($ $ ('$ LastName'); $ ("yourFrom"); submit (function () {var firstNameIsValid = Valid ($ ('# firstName')); if (last name)! NameIsValid) Amp; amp; (LastNameIsValid) {return false; // user has already been updated}})}};   

Also, because you already have your verification JavaScript is being heavily used (hope that this is the feature and not the only protection) The submit button can deactivate completely until that form does not meet the appropriate requirements.

No comments:

Post a Comment