PDA

View Full Version : How to disable a blur event


Vermelh0
11-14-2002, 05:20 PM
I have a text input that whenever a user types stuff into it, will do a postback and will use the stuff he typed as a key to find stuff from a database.
But, whenever a user uses a key that is not valid (i.e. does not exist on the database) I use onblur to trap him in the field until he enters something valid, or clears the information. Like this:

function sendError(o)
{
if ((o.value == o.oldvalue)
{
alert(alertMsg);
o.focus();
o.select();
}
}

<input type="text" onblur="sendError(this)" value="23" oldvalue="23" onchange="doPostBack()">

My problem is that I have a cancel button that takes the user away from the page, and I want to program something that when a user presses the button the sendError function won't execute allowing the page to postback.
Right now as the page is, a user can't click the cancel button until something is valid, which is not what I want....
Any help would be appreciated,
Thank you,
V

beetle
11-14-2002, 05:35 PM
Don't use onBlur. Switch to onChange or do this data-checking with the form's onSubmit.

Vermelh0
11-14-2002, 05:40 PM
>Switch to onChange or do this data-checking with the form's onSubmit

But onchange only activates when a user changes the value inside the text field. I need to create a popup everytime a user tries to leave the field, even if the field didn't changed.
And I really can't use the onSubmit, because I use that field to bring information from the database that is needed on other controls.

V

beetle
11-14-2002, 05:58 PM
Wait, why can't you use onSubmit? Because something already uses onSubmit? Surely they can both be done....

Vermelh0
11-14-2002, 06:25 PM
Hum... Think about this....
I have 20 controls on a page (radiobuttons, checkboxes, text fields, buttons, etc)
Down on the 5th control, I have one that when a user types an ID, the control will postback the page and the server code go into the database with that ID to fill in my remaining inputs. It will also close up the first 5 controls so that the user can no longer change them.
After the user changes what he needs in the open controls, he submits the page and everything is automatically saved into the database.
If the ID is invalid I can't do anything of what I just said, so I'm trying to force the user into entering a valid ID on that input before moving on.
V

beetle
11-14-2002, 06:35 PM
hmmm, how about something like this?

<input type="text" name="code" value="Enter Code" onBlur="if (/^\s*$/.test(this.value)) this.value='Enter Code';" />

Then, if the form is submitted and code == 'Enter Code' then you can kick it back.

Will that work??