rahulgupta wrote:
i have a textbox and a save_btn which is a hyperlink.
Make the latter a submit button and your problems will go away.
function KeyDownHandler(e , btn_Save)
^
It is not a constructor, so it should not look like one.
{
var browser=navigator.appName;
evt = e || window.event ;
if (evt.keyCode == 13|| evt.which == 13)
{
if(browser == "Microsoft Internet Explorer" )
Browser sniffing is an error-prone practice that is unnecessary here, ...
{
evt.returnValue=false;
evt.cancel = true;
document.getElementById(btn_Save).click();
.... you should feature-test whether your objects have those properties instead.
<http://PointedEars.de/scripts/test/whatamipp.
}
else
{
evt.preventDefault();
evt.returnValue=false;
^^^^^^^^^^^^^^^^^^^^^^
evt.cancel = true;
^^^^^^^^^^^^^^^^^^
Why two branches for that at all?
var e1 = document.createEvent('HTMLEvents');
e1.initEvent('click', false, false);
`click' is implemented as a *mouse* event, so it would have to be
`MouseEvents' and the initEvent() call would be missing several arguments.
document.getElementById(btn_Save).dispatchEvent(e1 );
}
}
}
and this is a code behind
txtbox1.Attributes.Add("onKeyDown", "javascript:KeyDownHandler(event ,
'"+ btn_Save + "');");
Wrong event, it is only suitable for printable characters. And since no
standard object would have an `Add' method, you are using some library; not
showing it makes it impossible for others to be sure what it does. But you
really do not need any of this. Quick hack:
<script type="text/javascript">
function keyDownHandler(e)
{
var c = e.charCode || e.keyCode;
if (c == 13)
{
postback();
return false;
}
return true;
}
<form action="..." method="post">
<textarea
onkeypress="if (typeof event != 'undefined')
return keyDownHandler(event)"
></textarea>
<input type="submit" value="Save">
</form>
However:
If you mean `textarea' by "textbox", there is no reason not to use an
`input' element instead, for you do not seem to want or need multi-line
input/display.
If you mean an `input' element by that, you need no scripting at all.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>