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.getEle mentById(btn_Sa ve).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=navigat or.appName;
evt = e || window.event ;
if (evt.keyCode == 13|| evt.which == 13)
{
if(browser == "Microsoft Internet Explorer" )
{
evt.returnValue =false;
evt.cancel = true;
document.getEle mentById(btn_Sa ve).click();
}
else
{
evt.preventDefa ult();
evt.returnValue =false;
evt.cancel = true;
var e1 = document.create Event('HTMLEven ts');
e1.initEvent('c lick', false, false);
document.getEle mentById(btn_Sa ve).dispatchEve nt(e1);
}
}
}
and this is a code behind
txtbox1.Attribu tes.Add("onKeyD own", "javascript:Key DownHandler(eve nt ,
'"+ 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.getEle mentById(btn_Sa ve).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=navigat or.appName;
evt = e || window.event ;
if (evt.keyCode == 13|| evt.which == 13)
{
if(browser == "Microsoft Internet Explorer" )
{
evt.returnValue =false;
evt.cancel = true;
document.getEle mentById(btn_Sa ve).click();
}
else
{
evt.preventDefa ult();
evt.returnValue =false;
evt.cancel = true;
var e1 = document.create Event('HTMLEven ts');
e1.initEvent('c lick', false, false);
document.getEle mentById(btn_Sa ve).dispatchEve nt(e1);
}
}
}
and this is a code behind
txtbox1.Attribu tes.Add("onKeyD own", "javascript:Key DownHandler(eve nt ,
'"+ btn_Save + "');");
Please somebody help me in solving this problem.
Comment