unemployment — 2011-06-13T15:07:12-04:00 — #1
function backspace_delete(e, delete_ele_id)
// IE reports window.event instead of the argument
e = window.event;
keycode = e.keyCode;
// Not IE
keycode = e.which;
if (keycode == 8 && with_field.value == '')
paul_wilkins — 2011-06-13T20:09:42-04:00 — #2
I'm investigating the cause, but first a small note on the formatting of your code.
One of these works as expected, the other one doesn't.
Try to work out why one of them doesn't work. It involves strange things like automatic-semicolon-insertion, designated code blocks, and strangely enough, labels.
paul_wilkins — 2011-06-13T20:18:00-04:00 — #3
I've attempted to also create some HTML and scripting code to use the above function, and in the process found that with_field is a variable that hasn't been defined.
Do you have a simple test page that demonstrates the use of your function? Because we can provide advice on how to improve what you are doing there.
unemployment — 2011-06-13T23:03:10-04:00 — #4
Link to the JS Fiddle
paul_wilkins — 2011-06-13T23:19:46-04:00 — #5
The problem stems from Internet Explorer. Who would have guessed.
IE doesn't fire the keypress event for special keys that don't change the field value. Such special keys include delete, end, enter, escape, function keys, home, insert, pageUp/Down and tab. It seems that Webkit (used for Chrome and Safari) decided to be compatible with Internet Explorer in this regard.
Techy details: detecting keystrokes
The onkeydown and onkeyup events do fire for those special keys though.
unemployment — 2011-06-13T23:21:30-04:00 — #6
So I suppose all I have to do is change it to an onkeydown function?
paul_wilkins — 2011-06-13T23:22:08-04:00 — #7
Try it out, what do you find?