I'm stuck in a blur/focus loop help me

Results 1 to 3 of 3

Thread: I'm stuck in a blur/focus loop help me

  1. #1
    Rob Reid Guest

    Default I'm stuck in a blur/focus loop help me

    I&#039;m validating a form. On the OnBlur event I check the fields contents and if its invalid I want the field to turn blue and the focus to be kept on it. At the moment I am in some kind of loop that freezes my machine.<BR>Heres the code<BR><BR>function setColor(el, bg) {<BR> if (el.style) el.style.backgroundColor = bg;<BR> }<BR><BR><BR>//************************************************** ****************************<BR><BR> function checkInputName(el) {<BR> <BR> alert("calling checkinputname"); <BR> <BR> <BR> if(validate(el)){<BR> alert(el.name + " validated ")<BR> setColor(el, bgGood);<BR> errormessage = "";<BR> document.frmTest.txtError.value = "";<BR> return true;<BR> }else{<BR> alert(el.name + " errors ")<BR> document.frmTest.txtError.value = errormessage<BR> setColor(el, bgBad)<BR> el.focus();<BR> errormessage = ""<BR> return false;<BR> }<BR> <BR> <BR> }<BR><BR>caliing the function thus<BR>&#060;INPUT type=Text maxlength=30 Name="Name" title="Name" tabindex=1 value="" nme="true" onBlur="return checkInputName(this)"&#062;<BR><BR>help me please why doesn&#039;t it just give the focus to the invalid field and then turn blue instead of going mad?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: I'm stuck in a blur/focus loop help me

    don&#039;t bother validating onBlur is my answer - you&#039;re just causing yourself hassle always do it the simplest way possible, then you can concentrate on the ACTUAL validation being correct, instead of the bells and whistles.<BR><BR>j

  3. #3
    Rob Reid Guest

    Default RE: I'm stuck in a blur/focus loop help me

    I got told by a Mr Bill Wilkinson that the way I was doing it was wrong, ie onChange, as I was missing out when they tab out of the txtbox.<BR>All I want is when the user comes out of a box it checks for correct input if its validated it moves on to the next box, if it isn&#039;t it turns it blue and focus remains on the incorrect box.<BR>I&#039;m trying to make it generic so I don&#039;t reference txtboxes explicitly.<BR>Also my boss doesn&#039;t want alert boxes so I have to check the boxes as they go along.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts