severndigital Posted January 1, 2011 Share Posted January 1, 2011 maybe i am going about this the wrong way .. but here is what i want to do 1. check a field input 2. if false clear the field and then 3. return focus to the empty field. I have this up and running at the following link http://chernay.homedns.org/mystore/signup/create_account the email field validates and check for incorrect email. function validate_email() { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(reg.test($('#emailaddress').val()) == false) { alert('Email Address does not appear to be valid.'); $("#emailaddress").val(''); $("#emailaddress").focus(); return false; } } the email address validates correctly, but when you type in something that isn't an email address. the alert pops up. but when you hit ok, it clears the field and moves the the next one. instead of going back to the email address field. any suggestions? I know it is my just doing something wrong, i just can't figure out what. thanks, Quote Link to comment https://forums.phpfreaks.com/topic/223130-focus-not-working-right/ Share on other sites More sharing options...
brianlange Posted January 1, 2011 Share Posted January 1, 2011 It's only an issue with ie. Your script should work fine with chrome or firefox. The hack is to insert a timeout with the focus call. setTimeout( function() { $("#emailaddress").focus(); } , 200); Quote Link to comment https://forums.phpfreaks.com/topic/223130-focus-not-working-right/#findComment-1153551 Share on other sites More sharing options...
severndigital Posted January 1, 2011 Author Share Posted January 1, 2011 That's what I thought too. But if you try the link you will see it doesn't work in any browser. Quote Link to comment https://forums.phpfreaks.com/topic/223130-focus-not-working-right/#findComment-1153571 Share on other sites More sharing options...
severndigital Posted January 1, 2011 Author Share Posted January 1, 2011 i got it working with your hack .. although it needed it be in there for any browser to work. thanks Quote Link to comment https://forums.phpfreaks.com/topic/223130-focus-not-working-right/#findComment-1153583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.