简体   繁体   中英

javascript is not working in mozilla but working in other browers

Technology Used:- Asp.Net 2.0

Code:- See Below
Description:- hello code given below is working fine in ie and other but not working in all mozila version.javascript is simple to devide two textbox's value. you can easily understand.

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

<!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" >
  <script type ="text/jscript">

var _txtamount;
var _txtins;
var _txtinsamount;

   function test() 
   {               
          var temp;
         _txtamount = document.getElementById("txtamount");
         _txtins = document.getElementById("txtins");
         _txtinsamount = document.getElementById("txtinsamount");

           if (_txtinsamount.value !='')
           {
             temp = parseFloat(_txtamount.value) / parseFloat(_txtinsamount.value);
           }
           else
           {
            temp = 0
           }               
           _txtins.value = temp;         
   }



</script>

<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="myform" runat="server" name="myform">
    <div>
        <asp:TextBox ID="txtamount" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtinsamount" runat="server" onblur="test();"></asp:TextBox>
        <asp:TextBox ID="txtins" runat="server"></asp:TextBox></div>
    </form>
</body>
</html>

Your <script> tag needs to be wrapped in the <head> element or in the <body> element; it can't just be a direct child of <html> .

[edit]more important is your "type" value, as the other answer here mentions.

You're using text/jscript as the <script> type. Use text/javascript instead:

<script type ="text/javascript">

JScript is Microsoft's own version of ECMAScript -- no wonder it works on IE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM