There may be situation where you may need to debug the javascript code. Mostly you need to identify any of the following
- Strange error by showing "!" mark in the bottom right corner of the browser especially in IE.
- Value assigned to a variable or a control
- Html control present in the webpage
- Conditional Check etc.,
Use the syntax debugger; inside a Javascript method and In IE goto Tools -> Internet Options -> Advance tab -> uncheck both Disable script debugging (Internet Explorer) and Disable script debugging (Others) to debug the Javascript method.
Please refer below sample code which I am reusing the earlier version of code.
<HTML>
<HEAD>
<HEAD>
<TITLE>Javascript
Eg.</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getValue() {
//In your case use the server tag here in place of "two" to //retrieve the saved value it vary from one server to other //server
//debugger the browser will start debugging from here
<SCRIPT LANGUAGE="JavaScript">
function getValue() {
//In your case use the server tag here in place of "two" to //retrieve the saved value it vary from one server to other //server
//debugger the browser will start debugging from here
debugger;
var servervalue = "two";
for(var i=0; i<document.getElementById("ItemList").options.length; i++)
{
if ( document.getElementById("ItemList").options[i].text == servervalue )
{
document.getElementById("ItemList").selectedIndex = i;
break;
}
}
}
//Method 1.
//window.onload = getValue;
</SCRIPT>
</HEAD>
<!--Method 2.-->
<BODY onload="Javascript:getValue();">
<P>
Sample Dropdownlist
<SELECT NAME="ItemList">
<OPTION VALUE="one">one
<OPTION VALUE="two">two
<OPTION VALUE="three">three
<OPTION VALUE="four">four
</SELECT></P>
</BODY>
</HTML>
var servervalue = "two";
for(var i=0; i<document.getElementById("ItemList").options.length; i++)
{
if ( document.getElementById("ItemList").options[i].text == servervalue )
{
document.getElementById("ItemList").selectedIndex = i;
break;
}
}
}
//Method 1.
//window.onload = getValue;
</SCRIPT>
</HEAD>
<!--Method 2.-->
<BODY onload="Javascript:getValue();">
<P>
Sample Dropdownlist
<SELECT NAME="ItemList">
<OPTION VALUE="one">one
<OPTION VALUE="two">two
<OPTION VALUE="three">three
<OPTION VALUE="four">four
</SELECT></P>
</BODY>
</HTML>
No comments:
Post a Comment