Results 1 to 5 of 5

Thread: Java Script - onBlur event goes infinite message

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    65

    Question

    I have a web page that need validation of input data ..
    and i have used onBlur event that calls ValidateField
    that checks whether the length of entered data in that
    field is greater than certain value(say 3 chars)..

    <INPUT NAME="FirstName" TYPE=TEXT SIZE=15 onBlur="validateField(this,3);" >

    function ValidateField(field,len)
    {
    if (field.length < len)
    {
    alert("Field must be at least " + minLen + "
    characters long!");
    field.focus();
    }
    }

    But, the problem is, the message keeps coming
    infinitely if less characters, say 2 chars is entered..
    It goes into infinite message display and it

    Is it a browser problem ?
    thanks
    sarath

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I'll tell you what the problem is...
    you have more than one textbox on your page and you are calling validateField onBlur of both/all of them.

    When you enter text in the box 1 and then go to box 2 box one is being validated. setting the focus to box 1 causes box 2 to be validated which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated,which then sets focus to box 2 causing box 1 to be validated, which then sets focus to box 1 causing box2 to to be validated

    ...and so on!
    Mark
    -------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    65

    thanks mark..is there any way out of it ?

    hi mark,
    You are perfectly right in saying that two
    text boxes are using this valid function.. i tried
    writing separate functions and calling them.. Still
    nothing happened.. the problem persists..
    I tried inserting a dummy text box in between these
    successive text boxes .. Still the problem persists..

    Is there any way out ??
    thanks once again..
    sarath

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    It would (probably) be better to do all you field checking last of all.

    Is the form going to be posted back to the server? if so, check all the fields before submiting.


    Mark
    -------------------

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    65

    Question thanks for the suggestion..

    hi mark,
    thanks..
    It is better to check the validations
    at the end ..

    sarath

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