开发者

Javascript: Acts different when test alert message is present

I have a text box function as below

开发者_如何学Python<input type="text" onkeypress="return onEnter(event,this);"
    onBlur="return chkForDBCS(this);"/>

function chkForDBCS() check if a DBCS(mainly for japanese char) is entered in the text and throws an alert message and clears the text box.

function onEnter() submits the form.

When i have test alert message on the beginning of onEnter() function, then on onBlur's chkForDBCS() is executed first and and waits till its completion to start on onEnter method.

But when i removed the test alert message in onEnter, then form is submitted(onEnter) and simultaneously alert message(from chkforDBCS) is displayed.

But my requirements are first to check if DBCS char is entered using chkForDBCS and once everything is fine, only then the form needs to be submitted.

Is there something like synchronization which i can use to solve the above problem.

Could anyone help me out on the above problem. Thanks in advance.


Use the onbeforesubmit event:

<form onbeforesubmit="onBeforeSubmitHandler()" ...>

You can return false from your event handler to prevent the form from being submitted.

Furthermore, why are you using onkeypress to submit the form? Don't you have a normal submit button?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜