Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Discuss The Relationship Between Javascript And Ecmascript?

Answer»

Javascript is a SCRIPTING language that has been widely accepted for CLIENT side web development. However it ORIGINATED from ECMA standards. ECMA and livescripts are just other names of java SCRIPT.

Javascript is a scripting language that has been widely accepted for client side web development. However it originated from ECMA standards. ECMA and livescripts are just other names of java script.

2.

How To Read And Write A File Using Java Script?

Answer»

This can be done in TWO ways which are discussed below,
1. Using an ActiveX objects (Internet Explorer only)
Using ActiveX objects, following should be INCLUDED in the code to read a file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\example.txt", 1, true);
2. By the use of JavaScript EXTENSIONS which RUNS from the Java Script EDITOR.
In JavaScript Extensions,
fh = fopen(getScriptPath(), 0); to open a file

This can be done in two ways which are discussed below,
1. Using an ActiveX objects (Internet Explorer only)
Using ActiveX objects, following should be included in the code to read a file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\example.txt", 1, true);
2. By the use of JavaScript extensions which runs from the Java Script editor.
In JavaScript Extensions,
fh = fopen(getScriptPath(), 0); to open a file

3.

What Are Windows Object And Navigator Object In Javascript?

Answer»

The top level object in java SCRIPT is the windows object. It further has several other objects such as document, LOCATION, history, menu bar, name, ETC. contained WITHIN itself. The global object on which client side java scripts are written is the windows object. Information regarding the client SYSTEM is returned by the Navigator browser of the script. For all users Navigator browsers are the base object.

The top level object in java script is the windows object. It further has several other objects such as document, location, history, menu bar, name, etc. contained within itself. The global object on which client side java scripts are written is the windows object. Information regarding the client system is returned by the Navigator browser of the script. For all users Navigator browsers are the base object.

4.

What Is Decodeuri(), Encodeuri() In Javascript?

Answer»

In order to transform the URL into its hexadecimal equivalent the encodeURI() and decodeURI() are used. This is done to send the CHARACTERS that by DEFAULT cannot be SPECIFIED in a URL.

For example, the following code snippet PERFORMS the encoding of URL:

var uri = http://agnlosticajams.weber.com; // original URI
var encodeuri=encodeURI(uri);
document.write("<br />necodeuri”);
var decodeuri = decodeURI(ncodeuri); 
document.write(“<br>/>decodeuri”);

In order to transform the URL into its hexadecimal equivalent the encodeURI() and decodeURI() are used. This is done to send the characters that by default cannot be specified in a URL.

For example, the following code snippet performs the encoding of URL:

var uri = http://agnlosticajams.weber.com; // original URI
var encodeuri=encodeURI(uri);
document.write("<br />necodeuri”);
var decodeuri = decodeURI(ncodeuri); 
document.write(“<br>/>decodeuri”);

5.

Discuss How Can We Access Elements Using Java Script?

Answer»

Each elements of JavaScript can be ACCESSED by their names. To access the page, document element is used and to access the BROWSER the windowelement is used in the SCRIPT. This element’s values are required for several computing reason say validation check. For EXAMPLE:
VAR myID = windows.document.formLogin.userID.value;

Each elements of JavaScript can be accessed by their names. To access the page, document element is used and to access the browser the windowelement is used in the script. This element’s values are required for several computing reason say validation check. For example:
var myID = windows.document.formLogin.userID.value;

6.

How Do We Get Javascript Onto A Web Page?

Answer»

The script ELEMENT can directly be added INSIDE the body of the PAGE. It should START with the TAG <script> and end with </script> tag. The script can also be added to the head tag of the web page. Similarly the other way is by placing the script in a separate file which gets downloaded on the client’s machine when the page is requested.

The script element can directly be added inside the body of the page. It should start with the tag <script> and end with </script> tag. The script can also be added to the head tag of the web page. Similarly the other way is by placing the script in a separate file which gets downloaded on the client’s machine when the page is requested.

7.

What Does Sticky Session Mean In A Web-farm Scenario?

Answer»

Sticky session is a characteristic which provides LOAD balancing solution for web farms for re-routing the request of the session to the machine which FIRST answered the request for that session. This ensures the session persistency in CASE when the session is ROUTED to other servers. Sticky session causes UNEVEN load distribution across servers.

Sticky session is a characteristic which provides load balancing solution for web farms for re-routing the request of the session to the machine which first answered the request for that session. This ensures the session persistency in case when the session is routed to other servers. Sticky session causes uneven load distribution across servers.

8.

How Can Javascript Make A Web Site Easier To Use?

Answer»

Javascripts RUN on the client side which saves the server roundtrip time for SMALL processing. It means that it makes web pages more interactive as everything is not REQUIRED to be submitted at the server. Let’s consider a small clock if CONTROLLED by the server then the transmission time will make the clock faulty in this case javascript is used.

Javascripts run on the client side which saves the server roundtrip time for small processing. It means that it makes web pages more interactive as everything is not required to be submitted at the server. Let’s consider a small clock if controlled by the server then the transmission time will make the clock faulty in this case javascript is used.

9.

What Are The Methods Of Validating Whether The Form Is Secure?

Answer»

Security of a form can be ensured by several ways some of them are:-
1. ACTION Attribute of the form- The form action attribute must start with https:// for ensuring the secure site.
2. Checking the Java Routine- In the Java routine theformname.action="specified URL” which should also begin with https:// for ensuring the secure site.
3. Checking the URL of the form itself whether it begins with https://
Any ONE of the CONDITION should be OBEYED by the web form else the form is not secured.

Security of a form can be ensured by several ways some of them are:-
1. Action Attribute of the form- The form action attribute must start with https:// for ensuring the secure site.
2. Checking the Java Routine- In the Java routine theformname.action="specified URL” which should also begin with https:// for ensuring the secure site.
3. Checking the URL of the form itself whether it begins with https://
Any one of the condition should be obeyed by the web form else the form is not secured.

10.

What Is The Main Difference Between Client Side Javascript And Server Side Java Script? How Actually They Run On Both Side?

Answer»

To state the main DIFFERENCE, JavaScript at the CLIENT SIDE does not require a web server to make it run instead it uses the client’s processor for this purpose. This eradicates the portability issue. But in server side JavaScript deployment, portability, configuration are major and vast issues and requires a web server to run the SCRIPT within a page before rendering its output as a response html page.

To state the main difference, JavaScript at the client side does not require a web server to make it run instead it uses the client’s processor for this purpose. This eradicates the portability issue. But in server side JavaScript deployment, portability, configuration are major and vast issues and requires a web server to run the script within a page before rendering its output as a response html page.

11.

What Is Java Script And What Are Their Functionalities?

Answer»

JavaScript is a CLIENT side scripting language that is mainly used to PERFORM client side processing to prevent server round trips and to make the USER response time faster. It is widely used for validation purpose such as confirm password validation and etc. It is GENERALLY embedded WITHIN the HTML which on client side is interpreted by the browser and the scripts are copy able.

JavaScript is a client side scripting language that is mainly used to perform client side processing to prevent server round trips and to make the user response time faster. It is widely used for validation purpose such as confirm password validation and etc. It is generally embedded within the HTML which on client side is interpreted by the browser and the scripts are copy able.

12.

What Is The Difference Between Javascript And Jscript?

Answer»

Jscript supports more rich set of functionality/commands than the java script, through which ActiveX and LOCAL COMPUTER can be accessed. These commands are used in an intranet where the connecting computer’s configuration is known and they are all being accessed USING INTERNET Explorer. While java script targets unknown machine configuration and Jscript cannot for which java script are suitable for internet which Jscripts are not.

Jscript supports more rich set of functionality/commands than the java script, through which ActiveX and local computer can be accessed. These commands are used in an intranet where the connecting computer’s configuration is known and they are all being accessed using Internet Explorer. While java script targets unknown machine configuration and Jscript cannot for which java script are suitable for internet which Jscripts are not.

13.

Decodeuri(), Encodeuri()

Answer»

Many CHARACTERS cannot be sent in a URL, but must be converted to their hex encoding. These functions are used to convert an entire URI (a superset of URL) to and from a format that can be sent VIA a URI. 
<script type="text/javascript">
var uri = "HTTP://www.google.com/search?q=sonofusion Taleyarkhan"
document.write("Original uri: "+uri);
document.write("<br />encoded: "+encodeURI(uri));
</script>

Many characters cannot be sent in a URL, but must be converted to their hex encoding. These functions are used to convert an entire URI (a superset of URL) to and from a format that can be sent via a URI. 
<script type="text/javascript">
var uri = "http://www.google.com/search?q=sonofusion Taleyarkhan"
document.write("Original uri: "+uri);
document.write("<br />encoded: "+encodeURI(uri));
</script>

14.

Unescape(), Escape()

Answer»

These are similar to the decodeURI() and encodeURI(), but escape() is used for only PORTIONS of a URI.

<script type="text/javascript">
var myvalue = "Sir WALTER Scott";
document.write("Original myvalue: "+myvalue);
document.write("<br />escaped: "+escape(myvalue));
document.write("<br />uri part: \"&author="+escape(myvalue)+"\"");
</script>

If you use escape() for the WHOLE URI... well bad things happen.
<script type="text/javascript">
var uri = "HTTP://www.google.com/search?q=sonofusion Taleyarkhan"
document.write("Original uri: "+uri);
document.write("
escaped: "+escape(uri));
v/script>

These are similar to the decodeURI() and encodeURI(), but escape() is used for only portions of a URI.

<script type="text/javascript">
var myvalue = "Sir Walter Scott";
document.write("Original myvalue: "+myvalue);
document.write("<br />escaped: "+escape(myvalue));
document.write("<br />uri part: \"&author="+escape(myvalue)+"\"");
</script>

If you use escape() for the whole URI... well bad things happen.
<script type="text/javascript">
var uri = "http://www.google.com/search?q=sonofusion Taleyarkhan"
document.write("Original uri: "+uri);
document.write("
escaped: "+escape(uri));
v/script>

15.

What's Prototypes For Javascript?

Answer»

Objects have "prototypes" from which they may INHERIT fields and functions.

<script type="text/javascript">
function movieToString() {
return("TITLE: "+this.title+" director: "+this.director);
}
function movie(title, director) {
this.title = title;
this.director = director || "unknown"; //if null assign to "unknown"
this.toString = movieToString; //assign function to this METHOD pointer
}
movie.prototype.isComedy = false; //add a field to the movie's prototype
var officeSpace = new movie("OfficeSpace");
var narnia = new movie("Narni","Andrew Adamson");
document.write(narnia.toString());
document.write("
Narnia a comedy? "+narnia.isComedy);
officeSpace.isComedy = true; //OVERRIDE the default just for this object
document.write("
OFFICE Space a comedy? "+officeSpace.isComedy);
</script>

Objects have "prototypes" from which they may inherit fields and functions.

<script type="text/javascript">
function movieToString() {
return("title: "+this.title+" director: "+this.director);
}
function movie(title, director) {
this.title = title;
this.director = director || "unknown"; //if null assign to "unknown"
this.toString = movieToString; //assign function to this method pointer
}
movie.prototype.isComedy = false; //add a field to the movie's prototype
var officeSpace = new movie("OfficeSpace");
var narnia = new movie("Narni","Andrew Adamson");
document.write(narnia.toString());
document.write("
Narnia a comedy? "+narnia.isComedy);
officeSpace.isComedy = true; //override the default just for this object
document.write("
Office Space a comedy? "+officeSpace.isComedy);
</script>

16.

How To Use "join()" To Create A String From An Array Using Javascript?

Answer»

"join" concatenates the ARRAY elements with a SPECIFIED seperator between them.

<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday", "THURSDAY","FRIDAY","SATURDAY"];
document.write("days:"+days.join(","));
</script>
This produces
days:Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

"join" concatenates the array elements with a specified seperator between them.

<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
document.write("days:"+days.join(","));
</script>
This produces
days:Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

17.

How To Use Strings As Array Indexes Using Javascript?

Answer»

Javascript does not have a true hashtable object, but through its wierdness, you can USE the ARRAY as a hashtable.

<script TYPE="text/javascript">
var days = ["SUNDAY","Monday","Tuesday","WEDNESDAY", "Thursday","Friday","Saturday"];
for(var i=0; i < days.length; i++) {
days[days[i]] = days[i];
}
document.write("days[\"Monday\"]:"+days["Monday"]);
</script>
This produces
days["Monday"]:Monday

Javascript does not have a true hashtable object, but through its wierdness, you can use the array as a hashtable.

<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
for(var i=0; i < days.length; i++) {
days[days[i]] = days[i];
}
document.write("days[\"Monday\"]:"+days["Monday"]);
</script>
This produces
days["Monday"]:Monday

18.

How To Delete An Entry Using Javascript?

Answer»

The "delete" operator removes an array element, but oddly does not CHANGE the size of the array.
<script TYPE="text/javascript">
VAR days = ["Sunday","Monday","TUESDAY","WEDNESDAY", "Thursday","Friday","Saturday"];
document.write("Number of days:"+days.length); delete days[4];
document.write("<br />Number of days:"+days.length);
</script>
This produces
Number of days:7
Number of days:7

The "delete" operator removes an array element, but oddly does not change the size of the array.
<script type="text/javascript">
var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
document.write("Number of days:"+days.length); delete days[4];
document.write("<br />Number of days:"+days.length);
</script>
This produces
Number of days:7
Number of days:7

19.

What Does The Delete Operator Do?

Answer»

The delete operator is used to delete all the variables and objects used in the PROGRAM ,but it does not delete variables DECLARED with var keyword.

The delete operator is used to delete all the variables and objects used in the program ,but it does not delete variables declared with var keyword.

20.

What's The Date Object Using Javascript?

Answer»

Time inside a date object is stored as MILLISECONDS since Jan 1, 1970. 
new Date(06,01,02) // produces "FRI Feb 02 1906 00:00:00 GMT-0600 (Central STANDARD Time)" 
new Date(06,01,02).toLocaleString() // produces "FRIDAY, February 02, 1906 00:00:00" 
new Date(06,01,02) - new Date(06,01,01) // produces "86400000"

Time inside a date object is stored as milliseconds since Jan 1, 1970. 
new Date(06,01,02) // produces "Fri Feb 02 1906 00:00:00 GMT-0600 (Central Standard Time)" 
new Date(06,01,02).toLocaleString() // produces "Friday, February 02, 1906 00:00:00" 
new Date(06,01,02) - new Date(06,01,01) // produces "86400000"

21.

What's Math Constants And Functions Using Javascript?

Answer»

The Math object contains useful CONSTANTS such as Math.PI, Math.E 
Math also has a zillion helpful functions. 
Math.abs(VALUE); //ABSOLUTE value 
Math.max(value1, value2); //find the largest 
Math.random() //generate a decimal NUMBER between 0 and 1 
Math.floor(Math.random()*101) //generate a decimal number between 0 and 100

The Math object contains useful constants such as Math.PI, Math.E 
Math also has a zillion helpful functions. 
Math.abs(value); //absolute value 
Math.max(value1, value2); //find the largest 
Math.random() //generate a decimal number between 0 and 1 
Math.floor(Math.random()*101) //generate a decimal number between 0 and 100

22.

How To Test For Bad Numbers Using Javascript?

Answer»

the global method, "isNaN()" can TELL if a number has GONE bad. 
var TEMPERATURE = parseFloat(myTemperatureWidget.value);
if(!isNaN(temperature)) {
alert("PLEASE enter a valid temperature.");
}

the global method, "isNaN()" can tell if a number has gone bad. 
var temperature = parseFloat(myTemperatureWidget.value);
if(!isNaN(temperature)) {
alert("Please enter a valid temperature.");
}

23.

How To Convert Numbers To Strings Using Javascript?

Answer»

You can prepend the number with an EMPTY string 
var MYSTRING = ""+myinteger; 
or 
var mystring = myinteger.toString(); 
You can specify a base for the CONVERSION
var myinteger = 14; 
var mystring = myinteger.toString(16);
mystring will be "E".

You can prepend the number with an empty string 
var mystring = ""+myinteger; 
or 
var mystring = myinteger.toString(); 
You can specify a base for the conversion, 
var myinteger = 14; 
var mystring = myinteger.toString(16);
mystring will be "e".

24.

How To Convert A String To A Number Using Javascript?

Answer»

You can use the parseInt() and parseFloat() methods. NOTICE that extra letters following a valid number are ignored, which is kinda wierd but convenient at times. 
parseInt("100") ==&GT; 100
parseFloat("98.6") ==> 98.6
parseFloat("98.6 is a common temperature.") ==> 98.6
parseInt("AA") ==> Nan //Not a Number
parseInt("aa",16) ==> 170 //you can SUPPLY a radix or base

You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times. 
parseInt("100") ==> 100
parseFloat("98.6") ==> 98.6
parseFloat("98.6 is a common temperature.") ==> 98.6
parseInt("aa") ==> Nan //Not a Number
parseInt("aa",16) ==> 170 //you can supply a radix or base

25.

How To Force A Page To Go To Another Page Using Javascript?

Answer»

<script LANGUAGE="JAVASCRIPT" TYPE="text/javascript" ><!-- location.href= "HTTP://newhost /newpath /newfile.html"; //--></script>

<script language="JavaScript" type="text/javascript" ><!-- location.href= "http://newhost /newpath /newfile.html"; //--></script>

26.

How To Reload The Current Page

Answer»

window.location.reload(TRUE);

window.location.reload(true);

27.

How To Set The Cursor To Wait.

Answer»

In THEORY, we should cache the current state of the CURSOR and then put it back to its original state. 
document.body.style.cursor = 'wait'; 
//do SOMETHING INTERESTING and time consuming
document.body.style.cursor = 'auto'; 

In theory, we should cache the current state of the cursor and then put it back to its original state. 
document.body.style.cursor = 'wait'; 
//do something interesting and time consuming
document.body.style.cursor = 'auto'; 

28.

How To Make Elements Invisible

Answer»

Change the "visibility" ATTRIBUTE of the style OBJECT associated with your element. REMEMBER that a hidden element still takes up space, use "DISPLAY" to MAKE the space disappear as well.

if ( x == y) {
myElement.style.visibility = 'visible';
} else {
myElement.style.visibility = 'hidden';
}

Change the "visibility" attribute of the style object associated with your element. Remember that a hidden element still takes up space, use "display" to make the space disappear as well.

if ( x == y) {
myElement.style.visibility = 'visible';
} else {
myElement.style.visibility = 'hidden';
}

29.

How To Change Style On An Element?

Answer»

Between CSS and javascript is a WEIRD symmetry. CSS STYLE rules are layed on TOP of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an ELEMENT can be swapped out. For example: 
document.getElementById("myText").style.color = "green";
document.getElementById("myText").style.fontSize = "20";
-or-
document.getElementById("myText").className = "regular";

Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an element can be swapped out. For example: 
document.getElementById("myText").style.color = "green";
document.getElementById("myText").style.fontSize = "20";
-or-
document.getElementById("myText").className = "regular";

30.

How To Getting Values From Cookies To Set Widgets?

Answer»

function getCookieData(labelName) {
//from Danny Goodman
var labelLen = labelName.length;
// read cookie property only once for SPEED
var cookieData = document.cookie;
var cLen = cookieData.length;
var i = 0;
var CEND;
while (i &LT; cLen) {
var j = i + labelLen;
if (cookieData.substring(i,j) == labelName) {
cEnd = cookieData.indexOf(";",j);
if (cEnd == -1) {
cEnd = cookieData.length;
}
return unescape(cookieData.substring(j+1, cEnd));
}
i++;
}
return "";
}

//init() is called from the body tag onload function.
function init() {
setValueFromCookie("brand");
setValueFromCookie("market");
setValueFromCookie("measure");
}

function setValueFromCookie(widget) {
if( getCookieData(widget) != "") {
document.getElementById(widget).value = getCookieData(widget);
}
}

//if you name your cookies the widget ID, you can use the FOLLOWING helper function
function setCookie(widget) {
document.cookie = widget + "=" +
ESCAPE(document.getElementById(widget).value) + getExpirationString();
}

function getCookieData(labelName) {
//from Danny Goodman
var labelLen = labelName.length;
// read cookie property only once for speed
var cookieData = document.cookie;
var cLen = cookieData.length;
var i = 0;
var cEnd;
while (i < cLen) {
var j = i + labelLen;
if (cookieData.substring(i,j) == labelName) {
cEnd = cookieData.indexOf(";",j);
if (cEnd == -1) {
cEnd = cookieData.length;
}
return unescape(cookieData.substring(j+1, cEnd));
}
i++;
}
return "";
}

//init() is called from the body tag onload function.
function init() {
setValueFromCookie("brand");
setValueFromCookie("market");
setValueFromCookie("measure");
}

function setValueFromCookie(widget) {
if( getCookieData(widget) != "") {
document.getElementById(widget).value = getCookieData(widget);
}
}

//if you name your cookies the widget ID, you can use the following helper function
function setCookie(widget) {
document.cookie = widget + "=" +
escape(document.getElementById(widget).value) + getExpirationString();
}

31.

How To Setting A Cookie With The Contents Of A Textbox ?

Answer»

Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them.

//SETS cookie of current VALUE for myTextBox
function TextBoxOnchange() {
var myBox = window.document.getElementById(myTextBox");
document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString();
}

//return a string like ";expires=Thu, 5 JAN 2006 16:07:52 UTC"
function getExpirationString() {
var EXP = new Date();
var threemonths = exp.getTime()+(120*24*60*60*1000);
exp.setTime(threemonths);
return ";expires="+exp.toGMTString();
}

This is called from the event handler in the HTML.

<input name="myTextBox" type="TEXT" id="myTextBox"
onchange="javascript:TextBoxOnchange()" />

Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them.

//Sets cookie of current value for myTextBox
function TextBoxOnchange() {
var myBox = window.document.getElementById(myTextBox");
document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString();
}

//return a string like ";expires=Thu, 5 Jan 2006 16:07:52 UTC"
function getExpirationString() {
var exp = new Date();
var threemonths = exp.getTime()+(120*24*60*60*1000);
exp.setTime(threemonths);
return ";expires="+exp.toGMTString();
}

This is called from the event handler in the HTML.

<input name="myTextBox" type="text" id="myTextBox"
onchange="javascript:TextBoxOnchange()" />

32.

How To Open A Window With No Toolbar, But With The Location Object.

Answer»

window.open("HTTP://www.mysite.org/Misc/PENNIES","Pennies","resizable=yes, status=yes,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,width=800,height=400");

window.open("http://www.mysite.org/Misc/Pennies","Pennies","resizable=yes, status=yes,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,width=800,height=400");

33.

How To Create An Input Box?

Answer»

PROMPT("What is your TEMPERATURE?");

prompt("What is your temperature?");

34.

How To Create A Confirmation Box?

Answer»

CONFIRM("Do you REALLY WANT to LAUNCH the MISSILE?");

confirm("Do you really want to launch the missile?");

35.

How To Create A Popup Warning Box

Answer»

ALERT('Warning: Please ENTER an INTEGER between 0 and 100.');

alert('Warning: Please enter an integer between 0 and 100.');

36.

How To Have The Status Line Update When The Mouse Goes Over A Link (the Support Of The Status Line Is Sporadic)?

Answer»

<a href="javascript.shtml" 
onmouseover="window.status='Hi There!';return true" 
onmouseout="window.status='';return true"&GT;LOOK at the Status bar</a>
Look at the Status bar as your cursor goes over the LINK.

<a href="javascript.shtml" 
onmouseover="window.status='Hi There!';return true" 
onmouseout="window.status='';return true">Look at the Status bar</a>
Look at the Status bar as your cursor goes over the link.

37.

How To Have An Element Invoke A Javascript On Selection, Instead Of Going To A New Url:

Answer»

&LT;script type="text/JAVASCRIPT"&GT;
FUNCTION pseudoHitMe() {
alert("Ouch!");
}
</script>
<a href="javascript:pseudoHitMe()">HIT me</a>

<script type="text/javascript">
function pseudoHitMe() {
alert("Ouch!");
}
</script>
<a href="javascript:pseudoHitMe()">hit me</a>

38.

How To Add New Elements Dynamically.

Answer»

<html xmlns="http://www.w3.org/1999/xhtml" xml:LANG="en" lang="en">
<head>
<TITLE>t1</title>
<SCRIPT type="text/javascript">
function addNode() {
var newP = document.createElement("p");
var textNode = document.createTextNode(" I'm a new text node");
newP.appendChild(textNode);
document.getElementById("firstP").appendChild(newP);
}
</script>
</head>
<BODY ONLOAD="addNode();" style=" background: url('../images/Sand-1280.jpg'); background-color: yellow;">
<p id="firstP">firstP<p>
</body>
</html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>t1</title>
<script type="text/javascript">
function addNode() {
var newP = document.createElement("p");
var textNode = document.createTextNode(" I'm a new text node");
newP.appendChild(textNode);
document.getElementById("firstP").appendChild(newP);
}
</script>
</head>
<body onload="addNode();" style=" background: url('../images/Sand-1280.jpg'); background-color: yellow;">
<p id="firstP">firstP<p>
</body>
</html>

39.

To Write Messages To The Screen Without Using "document.write()" ?

Answer»

CHANGING the contents of an element is a much better solution. When the method showStatus is invoked it will CHANGE the CONTENT of the span. 
...
function showStatus(message) {
var element = document.getElementById("mystatus");
element.textContent = message; //for FIREFOX
element.innerHTML = message; //for IE (why can't we all just get along?)
return true;
}
...
<span id="mystatus">Test. </span>

Changing the contents of an element is a much better solution. When the method showStatus is invoked it will change the content of the span. 
...
function showStatus(message) {
var element = document.getElementById("mystatus");
element.textContent = message; //for Firefox
element.innerHTML = message; //for IE (why can't we all just get along?)
return true;
}
...
<span id="mystatus">Test. </span>

40.

How To Disable An Html Object

Answer»

document.getElementById("myObject").DISABLED = TRUE;

document.getElementById("myObject").disabled = true;

41.

How To Find Radio Button Selection When A Form Is Submitted?

Answer»

<SCRIPT type="text/javascript"> 
function findButton() {
var myForm = document.forms.animalForm;
var i;
for(i=0;i<myForm.MARSUPIAL.length; i++) {
if(myForm.marsupial[i].checked) {
break;
}
}
alert("You selected ""+myForm.marsupial[i].value+"".");
}
</script>
<form name="animalForm" action="">
<INPUT type="radio" name="marsupial" value="KANGAROO" />Kangaroo
<br /><input type="radio" name="marsupial" value="Opossum" />Opossum
<br /><input type="radio" name="marsupial" value="Tasmanian Tiger" />Tasmanian Tiger
<input type="button" name="GO" value="GO" onclick="findButton()" />

<script type="text/javascript"> 
function findButton() {
var myForm = document.forms.animalForm;
var i;
for(i=0;i<myForm.marsupial.length; i++) {
if(myForm.marsupial[i].checked) {
break;
}
}
alert("You selected ""+myForm.marsupial[i].value+"".");
}
</script>
<form name="animalForm" action="">
<input type="radio" name="marsupial" value="kangaroo" />Kangaroo
<br /><input type="radio" name="marsupial" value="Opossum" />Opossum
<br /><input type="radio" name="marsupial" value="Tasmanian Tiger" />Tasmanian Tiger
<input type="button" name="GO" value="GO" onclick="findButton()" />

42.

How To Find The Selected Radio Button Immediately Using The 'this' Variable?

Answer»

&LT;script>
function favAnimal(button) {
alert('You LIKE '+button.value+'s.');
}
</script>
<input type="RADIO" NAME="marsupial" value="kangaroo"
onchange="favAnimal(this)">Kangaroo
<br /><input type="radio" name="marsupial" value="Opossum" 
onchange="favAnimal(this)">Opossum
<br /><input type="radio" name="marsupial" value="Tasmanian Tiger"
onchange="favAnimal(this)">Tasmanian Tiger

<script>
function favAnimal(button) {
alert('You like '+button.value+'s.');
}
</script>
<input type="radio" name="marsupial" value="kangaroo"
onchange="favAnimal(this)">Kangaroo
<br /><input type="radio" name="marsupial" value="Opossum" 
onchange="favAnimal(this)">Opossum
<br /><input type="radio" name="marsupial" value="Tasmanian Tiger"
onchange="favAnimal(this)">Tasmanian Tiger

43.

What Is === Operator ?

Answer»

==== is STRICT equality operator ,it returns TRUE only when the TWO operands are having the same value without any type conversion.

==== is strict equality operator ,it returns true only when the two operands are having the same value without any type conversion.

44.

What Are Undefined And Undeclared Variables?

Answer»

Undeclared variables are those that are not declared in the program (do not exist at all),TRYING to read their values gives runtime error.But if undeclared variables are assigned then IMPLICIT DECLARATION is done .

Undefined variables are those that are not assigned any value but are declared in the program.Trying to read such variables gives SPECIAL value CALLED undefined value.

Undeclared variables are those that are not declared in the program (do not exist at all),trying to read their values gives runtime error.But if undeclared variables are assigned then implicit declaration is done .

Undefined variables are those that are not assigned any value but are declared in the program.Trying to read such variables gives special value called undefined value.

45.

Does Javascript Have The Concept Level Scope?

Answer»

No.Javascript does not have block LEVEL scope,all the variables DECLARED INSIDE a function possess the same level of scope unlike C,c++,java.

No.Javascript does not have block level scope,all the variables declared inside a function possess the same level of scope unlike c,c++,java.

46.

What Is Variable Typing In Javascript?

Answer»

It is perfectly legal to ASSIGN a number to a variable and then assign a STRING to the same variable as follows 
example 
i = 10;
i = "string";
This is CALLED variable typing

It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows 
example 
i = 10;
i = "string";
This is called variable typing

47.

What Is The Difference Between Undefined Value And Null Value?

Answer»

(i)UNDEFINED VALUE cannot be explicitly STATED that is there is no keyword called undefined whereas null value has keyword called null
(II)typeof undefined VARIABLE or property returns undefined whereas typeof null value returns object

(i)Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null
(ii)typeof undefined variable or property returns undefined whereas typeof null value returns object

48.

What Does Undefined Value Mean In Javascript?

Answer»

Undefined value MEANS the VARIABLE used in the CODE DOESNT exist or is not assigned any value or the PROPERTY doesnt exist.

Undefined value means the variable used in the code doesnt exist or is not assigned any value or the property doesnt exist.

49.

How To Select An Element By Id And Swapping An Image ?

Answer»

<script language="JavaScript" type="text/javascript" >
function setBeerIcon() {
var beerIcon = document.getElementById("beerIcon");
beerIcon.src = "IMAGES/"+getSelectValue("BEER")+".JPG";
}
</script>
<img border="0" src="" ID="brandIcon" alt="BRAND" />
<select name="beer" id="beer" onChange="setButton();setBeerIcon();">
<option value="--Select--">Select beer</option>
<option value="heineken">heineken</option>
<option value="sol">sol</option>
<option value="amstellight">amstellight</option>
<option value="coronalight">coronalight</option>
<option value="coronaextra">coronaextra</option>
<option value=""></option>
</select>

<script language="JavaScript" type="text/javascript" >
function setBeerIcon() {
var beerIcon = document.getElementById("beerIcon");
beerIcon.src = "images/"+getSelectValue("beer")+".jpg";
}
</script>
<img border="0" src="" id="brandIcon" alt="brand" />
<select name="beer" id="beer" onChange="setButton();setBeerIcon();">
<option value="--Select--">Select beer</option>
<option value="heineken">heineken</option>
<option value="sol">sol</option>
<option value="amstellight">amstellight</option>
<option value="coronalight">coronalight</option>
<option value="coronaextra">coronaextra</option>
<option value=""></option>
</select>

50.

To Set All Checkboxes To True Using Javascript?

Answer»

//SELECT all input TAGS 
function SelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i<checkboxes.length;i++) {
if(checkboxes.item(i).attributes["TYPE"].value == "CHECKBOX") {
checkboxes.item(i).checked = true;
}
}
}

//select all input tags 
function SelectAll() {
var checkboxes = document.getElementsByTagName("input");
for(i=0;i<checkboxes.length;i++) {
if(checkboxes.item(i).attributes["type"].value == "checkbox") {
checkboxes.item(i).checked = true;
}
}
}