PDA

View Full Version : focus problem


homerUK
10-29-2003, 02:49 PM
hey,

I've got a simple form with some validation... when a user enters an incorrect value, it alerts them and clears the field... I then wanted it to focus back on that field.

my Js is:


function check(what)
{
value = what.value;

if (value > 100)
{
alert("cannot be greater than 100");
what.value = "";
what.focus();
return false;

}
}


then I have a text field like the following:


<input name="a" type="text" id="a" onChange="check(this)">


so when the value is changed it will check it, and if greater than 100, alert an error, clear the field (which both work) but the focus moves to the next field.

what am I doing wrong?!

thanks!

Matt

Kor
10-30-2003, 08:55 AM
I think you forgot to specify the return condition on event handler:

<input name="a" type="text" id="a" onChange="return check(this)">

homerUK
10-30-2003, 09:36 AM
cheers! thats worked perfectly! :)

Kor
10-30-2003, 09:47 AM
Ok... I will be always glad to help someone who lives in Manchester, even if he is not a fan of MANUTD, as I am...:)

homerUK
10-30-2003, 11:51 AM
well, dont worry.. I am! we got a season ticket for old trafford... so pretty big fans! :) :)