Set - 5

Question 1 :

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;

Question 2 :

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";
<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>

Question 3 :

What does undefined value mean in javascript?

Answer :

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

Question 4 :

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

Question 5 :

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
i = 10;
i = "string";
This is called variable typing