Forum Moderators: open

Message Too Old, No Replies

setting the focus

         

pithhelmet

5:59 pm on May 3, 2004 (gmt 0)

10+ Year Member



Hi Everyone -

I am trying to perform client side validation -
and would like to have the focus return to the
textbox that holds the error -

right now it just jumps to the next box
when there is an error -

what is the correct way to set focus on a textbox?

thanks
tony

moltar

6:09 pm on May 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.FORM_NAME.TEXT_FIELD_NAME.focus()

pithhelmet

7:26 pm on May 3, 2004 (gmt 0)

10+ Year Member



Ah hah!

thats what i thought - but i wasn't for sure.

In my onchange event in the textbox....

<input type=text class="inactive-area"
maxlength=10
name="st"
onchange="checkTestTime(this);">

My javascript function is....

function checkTestTime(a)
{
var ok = false;

if (IsValidTime(a.value))
{
alert("1");
}
else
{

alert("here");
a.focus();
// document.Form1.st.focus();
return true;
}
}

The IsValidTime(a.value)
returns true or false based on the value.

But the field just gets skipped
and the next field is made active...

any suggestions would be appreciated

thanks
tony