This method is used to get the elements after given specified id. Using this method we can get value from the input text field. But before to get value from input field , we need to define id for the input field.
Syntax:
document.getElementById("name") ;
Example :
Javascript Code :
fun multiply()
var a = document.getElementById("mul") ;
alert("Result is :"+a*a*a);
}
Html Code :
Enter Number :
<form>
<input type = "text" id = "mul" name = "number"/>
<input type = "button" value = "Click to see multiplication" onclick = "multiply()" />
</form>
Output :
Result is 8 // If you pass the value " 2 " in input field
0 Comment(s)