/    Sign up×
Community /Pin to ProfileBookmark

onClick event conflicts with Enter Key event

Dear all,

I tried to forward key focus like this

username text field-> password text field -> Submit button -> and then Form is submitted. Only after focus has passed password text filed, onsubmit() is allowed to call. It worked in all browsers. But unfortunately, before filling nothing in username and password fields, mouse clicking on submit button doesnt make form submit because key focus hasn’t passed password field. So I use onClick event to allow form submit. It works in IE and doesnt conflict with former key focus style. But in other browsers, original key focus style is lost. When Enter/Return key in username field is pressed, focus doenst go to password field. Instead of it, form is submitted. Onclick event conflicts with Key event. ( sorry for my English. And thanks for Mr Pittimann. I modified your code as necessary. )

<SCRIPT LANGUAGE=”JavaScript”>
var nextfield=’Email’;
dom=((document.getElementById&&!document.all)||window.opera);
function keyDown(e)
{
k=(dom)?e.which:event.keyCode;
if(k==13)
{
if(nextfield==’done’)
{
document.login_form.flag.value = “true”;
return true;
}
else
{
document.login_form[nextfield].focus();
return false;
}
}
}
document.onkeydown=function(e){return keyDown(e)};

<body>
<form name=”login_form” action=”second.php” method=”post” onsubmit=”if (document.login_form.flag.value == ‘false’) return false”

<input name=”Email” type=”text” onFocus=”nextfield =’pwd’;” >
<input name=”pwd” type=”password” onFocus=”nextfield =’done’;”>
input type=”image” name=”done” src=”btn-submit.gif” onClick=”document.login_form.flag.value = ‘true’;”>
<input type=”hidden” name=”flag” value=”false”>

</body>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMar 11.2005 — Hi!

So you want to allow submit if one or both fields are empty and the button is clicked? If so, use onmousedown instead of onclick.

Cheers - Pit
Copy linkTweet thisAlerts:
@mitchell_1078authorMar 11.2005 — Thank you so much friend. I didn't get an idea to use mousedown instead of onclick. (how stupid I am?) Really thank you so much.

regards,

Mitchell
Copy linkTweet thisAlerts:
@PittimannMar 11.2005 — Hi!

You're welcome. ?

Regards - Pit
×

Success!

Help @mitchell_1078 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...