HelloBD
HelloBD

Reputation: 387

why javascript not work on masterpage

work on asp.net vs 05 C#.Master page header contain the bellow code

<script type="text/javascript" language="javascript" src="JScript.js"></script>

from my one page i call the javascript method

 <asp:TextBox ID="txtLength" runat="server" >0</asp:TextBox>

 <asp:TextBox ID="txtHeight" runat="server" onchange="javascript:DoChange();">0</asp:TextBox>

javascript method is below :

 {
      alert("hello world");**//get this alert but don't get the bellow alert.**
     var a=document.getElementById("txtLength");
     var b=document.getElementById("txtHeight");
      alert(a.value*b.value);
   }

want to show value on message box .Actually want to calculate the Sft,How to ?

Upvotes: 0

Views: 1227

Answers (2)

recursive
recursive

Reputation: 86172

The DOM ID of the text boxes is not the same as the server side asp.net ID. In order to get the client DOM ID, use the ClientID property:

 var a=document.getElementById("<%= txtLength.ClientID %>");
 var b=document.getElementById("<%= txtHeight.ClientID %>");

Also, you are attempting to multiply two strings together even if that works.

More generally, I recommend using a javascript debugger like Firebug or Chrome's debugger. Then you will be able to see precisely what line the errors are occurring on and what they are.

Upvotes: 2

Related Questions