R
rahulgupta
i have a textbox and a save_btn which is a hyperlink. when ever enter
key is pressed there is a javascript which check if the name in the
textbox contains any special characters. but when we press enter it do
page postback and does not check for special characters.
i have written a javascript function which stops the post back on
enter press in textbox. and then i raise the onclick event by
document.getElementById(btn_Save).click(). in IE it works fine, but,
for mozilla and safari it just do the post back on enter key press.
I also tried to dispatch a event for mozilla but it isn't working.
Here is my code
function KeyDownHandler(e , btn_Save)
{
var browser=navigator.appName;
evt = e || window.event ;
if (evt.keyCode == 13|| evt.which == 13)
{
if(browser == "Microsoft Internet Explorer" )
{
evt.returnValue=false;
evt.cancel = true;
document.getElementById(btn_Save).click();
}
else
{
evt.preventDefault();
evt.returnValue=false;
evt.cancel = true;
var e1 = document.createEvent('HTMLEvents');
e1.initEvent('click', false, false);
document.getElementById(btn_Save).dispatchEvent(e1);
}
}
}
and this is a code behind
txtbox1.Attributes.Add("onKeyDown", "javascript:KeyDownHandler(event ,
'"+ btn_Save + "');");
Please somebody help me in solving this problem.
key is pressed there is a javascript which check if the name in the
textbox contains any special characters. but when we press enter it do
page postback and does not check for special characters.
i have written a javascript function which stops the post back on
enter press in textbox. and then i raise the onclick event by
document.getElementById(btn_Save).click(). in IE it works fine, but,
for mozilla and safari it just do the post back on enter key press.
I also tried to dispatch a event for mozilla but it isn't working.
Here is my code
function KeyDownHandler(e , btn_Save)
{
var browser=navigator.appName;
evt = e || window.event ;
if (evt.keyCode == 13|| evt.which == 13)
{
if(browser == "Microsoft Internet Explorer" )
{
evt.returnValue=false;
evt.cancel = true;
document.getElementById(btn_Save).click();
}
else
{
evt.preventDefault();
evt.returnValue=false;
evt.cancel = true;
var e1 = document.createEvent('HTMLEvents');
e1.initEvent('click', false, false);
document.getElementById(btn_Save).dispatchEvent(e1);
}
}
}
and this is a code behind
txtbox1.Attributes.Add("onKeyDown", "javascript:KeyDownHandler(event ,
'"+ btn_Save + "');");
Please somebody help me in solving this problem.