Javascript code not working in mozilla firefox?

Posted by Prabu_Spark under ASP.NET on 5/4/2013 | Points: 10 | Views : 1621 | Status : [Member] | Replies : 2
Hi sir,
I wrote one javascript code to prevent "space" in textbox. Its working fine in Internet explorer, but it is not working in mozilla firefox. I attached the code below for your reference. Kindly give me the solution for this problem.


Default3.aspx
*******************

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function AvoidSpace() {
if (event.keyCode == 32) {
event.returnValue = false;
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmpName" runat="server" onkeypress="return AvoidSpace()"></asp:TextBox>
</div>
</form>
</body>
</html>

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Jpchoudhari on: 5/4/2013 [Member] Starter | Points: 25

Up
0
Down
Modify below lines from your code

<asp:TextBox ID="txtEmpName" runat="server" onkeypress="return AvoidSpace(event)"></asp:TextBox> // pass event obj

function AvoidSpace(event) {
if (event.keyCode == 32) {
event.returnValue = false;
return false;
}
}

Kind Regards,
Jay

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/5/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
What is the error ?

Thank you for posting at Dotnetfunda
[Administrator]

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response