|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Javascript questionhi,
I'm trying to detect changes in a textbox to set a flag in javascript. I hook into the text boxes keypress event, which works fine except when you press the backspace key. In this case, the keypress event is not raised, and my flag never gets set. Any ideas? Thanks Andy On Jul 6, 9:00 pm, Andy <ajj3***@alum.rit.edu> wrote:
> I'm trying to detect changes in a textbox to set a flag in Oh, I also tired the change event, but that doesn't fire until after> javascript. I hook into the text boxes keypress event, which works > fine except when you press the backspace key. In this case, the > keypress event is not raised, and my flag never gets set. the control loses focus. Thanks Hi Andy,
According to me "onkeyup" event will work for you. But the downside is that it will be fired too many times. However you can detach the event after the first KeyUp with something like following: <script type="text/javascript"> function checkChanged( tfValue ) { alert( "In function" ); document.getElementById( "hdChanged" ).value = "true"; tfValue.setAttribute( "onkeyup", "" ); } </script> <form id="frmMain" action="test.html"> <input type="text" onkeyup="checkChanged( this );" /> <input type="hidden" id="hdChanged" name="hdChanged" value="false" /> </form> If you are looking to set the flag only when a specific Key is pressed then do so by comparing the value of "event.keyCode" with that specific Key's Key Code. For Javascript Char Codes visit the following: http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx Please let me know if it helps. regards, Joy Show quoteHide quote "Andy" wrote: > On Jul 6, 9:00 pm, Andy <ajj3***@alum.rit.edu> wrote: > > I'm trying to detect changes in a textbox to set a flag in > > javascript. I hook into the text boxes keypress event, which works > > fine except when you press the backspace key. In this case, the > > keypress event is not raised, and my flag never gets set. > > Oh, I also tired the change event, but that doesn't fire until after > the control loses focus. > > Thanks > "Joy" <J**@discussions.microsoft.com> wrote in message This will work only in IE. For cross-browser compatibility, you will need news:5EC950CF-A6FE-422F-B464-3C099E83D449@microsoft.com... > If you are looking to set the flag only when a specific Key is pressed > then > do so by comparing the value of "event.keyCode" with that specific Key's > Key > Code. something like: var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; if (keyCode == 13) // Enter key { // do something }
Other interesting topics
Gridview render control error in content page
Advice required Brwoser and screen width? Server.ScriptTimeout not being observed? VB.Net Developer, Houstan TX, Duration: 6months, ONLY Green Card / (1-140 & EAD approved) Problems adding HyperLink controls through code. Control is null on postback? DAL for sharing? The page cannot be found error message CSS menu |
|||||||||||||||||||||||