views:

72

answers:

2

Technology Used:- Asp.Net 2.0

Code:- See Below
Description:- hello code given below is working fine in i.e. 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"&gt;

<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>
+3  A: 

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.

Pointy
Indeed, any deviation from the specs has more chance of yielding unexpected results. Or just a failure.
Dykam
No dice. <script> under <html> works just fine in Firefox. What's important is the script type.
Ates Goral
@Ates yea you're right - I could swear I've had problems in the past with `<script>` tags *after* the `<body>`, but even that works for me now in a test page. Still, hanging scripts outside the head or body is a little ugly, at least.
Pointy
@Pointy - you can put script tags anywhere (not necessarily compliant XHTML), but you can do it. In fact, in general, you should put your scripts closer to the bottom of the HTML if possible, see http://developer.yahoo.com/performance/rules.html
nickyt
Yes thanks - I'm aware of the advantages of loading scripts towards the end of the DOM.
Pointy
+3  A: 

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.

Ates Goral
thaks. it's now working.
Nikunj Nandaniya