Jump to content


Photo

problems with .focus()


  • Please log in to reply
3 replies to this topic

#1 mb81

mb81
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 15 May 2006 - 04:53 PM

I have a problem with the javascript below. It seems that it will select, but not focus, what am I doing wrong?

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;
    }
}


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 May 2006 - 07:13 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 mb81

mb81
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 15 May 2006 - 08:12 PM

[!--quoteo(post=374094:date=May 15 2006, 03:13 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ May 15 2006, 03:13 PM) View Post[/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.


#4 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 18 May 2006 - 01:37 AM

Hi,,

That one works,... tested with both FF & IE
<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>
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,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users