Enabling javascript in browsers


To enable java script in you browser, please follow the instructions below:

Internet Explorer (6.0)

1. Select ‘Tools’ from the top menu
2. Choose ‘Internet Options’
3. Click on the ‘Security’ tab
4. Click on ‘Custom Level’
5. Scroll down until you see section labled ‘Scripting’
6. Under ‘Active Scripting’, select ‘Enable’ and click OK

Netscape Navigator (4.8)

1. Select ‘Edit’ from the top menu
2. Choose ‘Preferences’
3. Choose ‘Advanced’
4. Choose ‘Scripts & Plugins’
5. Select the ‘Enable JavaScript’ checkbox and click OK

Mozilla Firefox (1.0)

1. Select ‘Tools’ from the top menu
2. Choose ‘Options’
3. Choose ‘Web Features’ from the left navigation
4. Select the checkbox next to ‘Enable JavaScript’ and click OK

Mozilla Firefox (1.5)

1. Select ‘Tools’ from the top menu
2. Choose ‘Options’
3. Choose ‘Content’ from the top navigation
4. Select the checkbox next to ‘Enable JavaScript’ and click OK

Apple Safari (1.0)

1. Select ‘Safari’ from the top menu
2. Choose ‘Preferences’
3. Choose ‘Security’
4. Select the checkbox next to ‘Enable JavaScript’

Numeric Validation in javaScript


var isNS4 = (navigator.appName==”Netscape”)?1:0;
function checkCharacter(event){
if(!isNS4){
if(event.keyCode == 8 || event.keyCode == 0 ) return true;
if(event.keyCode < 46 || event.keyCode > 57 ) {
event.returnValue = false;
}
}
else{
if(event.which == 8 || event.which == 0 ) return true;
if(event.which < 46 || event.which > 57 ) {
return false;
}
}
}

Creation of Dynamic rows in javascript


Create a html file with this code and check the functionality:

<html>
<head>
<script LANGUAGE=”JavaScript”>
function addRow(tableID){
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement(“input”);
element1.type = “text”;
element1.name = “empNo”;
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
var element2 = document.createElement(“input”);
element2.type = “text”;
cell2.appendChild(element2);

var cell3 = row.insertCell(2);
var element3 = document.createElement(“textarea”);
element3.setAttribute(“name”,”mytextarea”);
element3.setAttribute(“cols”,”10″);
element3.setAttribute(“rows”,”1″);
cell3.appendChild(element3);
}
function deleteRow(tableID) {

var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if(rowCount > 1) {
table.deleteRow(rowCount – 1);
}

}
</script>
</head>
<body>
<form name=”f1″ id=”f1″>
<input type=”button”value=”Add” onclick=”addRow(‘datatable’)”>
<table id=”datatable” cellspacing=”0″ border=”1″ bgcolor=”#738711″>
<tbody>
<tr>
<td><input type=”text” ></td><td><input type=”text”></td><td><textarea rows=”1″ cols=”10″></textarea></td>

<td><a href=”javascript:void(0);” onclick=”deleteRow(‘datatable’)” >Remove</a></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Conversion of string into uppercase


The below function is used to convert the alphabets into uppercase

function convertToUpper(){
var field1 = document.formName.elementName

field1.value = field1.value.toUpperCase();
}

Example :
If the formName is StudentForm and element name is student id like stud100

Then ,
function convertToUpper(){
var field1 = document.StudentForm.StudentId

field1.value = field1.value.toUpperCase();

}

gives the value as STUD100.