Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reset onFocus : possible or not?

Status
Not open for further replies.

HollyVally

Programmer
Jan 3, 2003
48
BD
Hi,
I have tried the following but it didn't work:

onFocus="javascript:resetme()"

Can somebody correct me please !
 
I am actually trying to refocus on a field on error. I can managed to do everything but the "focus"-ing again on the field.

I need to refocus on the field!
 
HollyVally
here's the syntax for focusing on a field
you would use the built in funcvtion in javascript focus()

so if you had the function
function onErrorFocus(str){
if (str.value == "") {
alert("error in field!");
str.focus();
return false;
} else {
return true;
}

in this case you would being passing this input object to the function such as
<input type=&quot;text&quot; name=&quot;email&quot; onBlur=&quot;return onErrorFocus(this)&quot;>

now when the user tabs away from the field the function runs and checks for the value to not be empty &quot;&quot; and returns either the alert on condition being met or returns true and thus goes on to the next field.


hope that helps out ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
I managed to make it as your guidance! But only in IE, cant do it on Mozilla! Can u pls tell me some work around for this. :)
 
best work around is to name your objects and work with that
for instance instead of doing
function onErrorReset(obj) {
if (obj.value == &quot;&quot;) {
alert(&quot;Invalid!&quot;);
obj.focus();
return false;
}

you would do

function onErrorFocus() {
if (document.formname.fieldname.value == &quot;&quot;) {
window.alert(&quot;Invalid!&quot;);
document.formname.fieldname.focus();
//not sure is the focus() function works in moz
return false;
}

then to call
<input type=&quot;fieldname&quot; onBlur=&quot;return onErrorFocus()&quot;>

this is a netscape safety net as well. ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Thanx. I think thats the same catch22: focus prbbly doesnt work on moz! my bad luck! I have to get it X-browser!

c u l8r!
---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top