views:

45

answers:

1

Hello,

I have a text box function as below

<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.

A: 

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?

jnylen