OCJP

Basic Java Script

JavaScript is Scripting Language that is used for various purpose at Client Side as well as Server Side.

<html>
	<head>
		<title>
		Java Script Demo
		</title>
	</head>

	<body>
		<form name="frm1" id="frm1">
		Enter Name :
		<input type="text" id="txtname" name="txtname" />
		<input type="button" name="btnshow" id="btnshow" value ="Show" onclick="return showData();"/>
	
		</form>
	</body>

	<script>
		function showData()
		{
			var nm= document.getElementById("txtname").value;
			alert("Hi " + nm);
		}
	</script>
</html>

Here Button Click will call showData() function.

document.getElementById(‘idhere’) : This function search for the element in current document with particular id.

<element>.value : is used to get the values of that particular element.

In above example whatever is written in txtname will be displayed as alert after clicking on button.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?