mb81 Posted May 15, 2006 Share Posted May 15, 2006 I have a problem with the javascript below. It seems that it will select, but not focus, what am I doing wrong?[code]function checkdata(itemname) { switch (itemname) { case 'emailconfirm' : if (document.editprofile.emailconfirm.value != document.editprofile.email.value) { alert('The email addresses you have entered do not match'); document.editprofile.emailconfirm.select(); document.editprofile.emailconfirm.focus(); } break; case 'passwordconfirm' : if (document.editprofile.password.value != document.editprofile.passwordconfirm.value) { alert('The passwords you have entered do not match.'); document.editprofile.passwordconfirm.select(); document.editprofile.passwordconfirm.focus(); } break; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9726-problems-with-focus/ Share on other sites More sharing options...
obsidian Posted May 15, 2006 Share Posted May 15, 2006 when you run select() on a text input field, the focus is put on that field. you shouldn't have to do focus() after that. Quote Link to comment https://forums.phpfreaks.com/topic/9726-problems-with-focus/#findComment-36052 Share on other sites More sharing options...
mb81 Posted May 15, 2006 Author Share Posted May 15, 2006 [!--quoteo(post=374094:date=May 15 2006, 03:13 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ May 15 2006, 03:13 PM) [snapback]374094[/snapback][/div][div class=\'quotemain\'][!--quotec--]when you run select() on a text input field, the focus is put on that field. you shouldn't have to do focus() after that.[/quote]My cursor is in the next field, I tried it .select, then .focus, I tries it .focus, then .select, or just .select, the cursor always seems to be in the next field. Quote Link to comment https://forums.phpfreaks.com/topic/9726-problems-with-focus/#findComment-36078 Share on other sites More sharing options...
GBS Posted May 18, 2006 Share Posted May 18, 2006 Hi,,That one works,... tested with both FF & IE[code]<html><head><title>Testing,,</title></head><body><script>function checkdata(itemname){switch (itemname) { case 'emailconfirm' : if (document.getElementById('emailconfirm').value != document.getElementById('email').value) { alert('The email addresses you have entered do not match'); document.getElementById('email').select(); } break; case 'passwordconfirm' : if (document.getElementById('pwdconfirm').value != document.getElementById('pwd').value) { alert('The passwords you have entered do not match.'); document.getElementById('pwd').select(); } break; }}</script>enter your mail: <input type="text" id="email"><br>confirm your mail: <input type="text" id="emailconfirm" onchange="checkdata('emailconfirm');"><br><br>set a password: <input type="password" id="pwd"><br>confirm your password: <input type="password" id="pwdconfirm" onchange="checkdata('passwordconfirm');"><br><script>//needed for firefox to reset the form,,document.getElementById('email').value="";document.getElementById('emailconfirm').value="";</script></body></html>[/code]I think your "document.editprofile.emailconfirm" method should be more document.forms['editprofile'].elements['emailconfirm'],,...I guess the problem is from there,...I prefer mostly the 'document.getElementById' method, giving an Id to each element needed,,... it gives me less error,,... question of preferences,, :)l8tr,, Quote Link to comment https://forums.phpfreaks.com/topic/9726-problems-with-focus/#findComment-36782 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.