Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wrote script for backspace event
that if i press backspace then focus on textbox
but one problem that it focus on textbox and it erase one letter
and i want to focus with no erase textbox value..
please give me slution for focus with press on backspace and no erase textbox any letter

C#
if(e.which==8)
{
      $("#txtsid").focus()
}
Posted

The reason is that BACKSPACE has its default behavior too - deleting one character...
If you want to stop the default behavior you have to stop the bubbling (propagation) of the event...
As you use jQuery you can benefit from event.stopPropagation()[^]
JavaScript
if(e.which==8)
{
  $("#txtsid").focus()

  e.stopPropagation();
}
 
Share this answer
 
v2
Comments
Manish Dalwadi 14-Dec-14 6:56am    
i wrote this yesterdaybut no effect
You can try to override the default function of the event, by using this code,

JavaScript
event.preventDefault();


.. write this line inside the very first line of the event handler, using which will prevent all of the default functions that it can perform and the remaining code will execute as it should.
 
Share this answer
 
Comments
Manish Dalwadi 14-Dec-14 6:57am    
i wrote this yesterdaybut no effect

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900