js1

Share this page :

confirm() :-
It displays the confirm dialog box containing message with ok and cancel button.
<html>
<body>
<script>
var s=confirm(“Are you ok?”);
if(s==true)
{
alert(“you pressed ok”);
}
else
{
alert(“you pressed cancel”);
}
</script>
</body>
</html>

 

prompt() :-
It displays a dialog box to get input from the user.
<html>
<body>
<script>
var k=prompt(“What is your name?”);
alert(“I am ” + k);
</script>
</body>
</html>

 

Accessing field value by document object:

In this example, we are going to get the value of input text by user. Here, we are using document.form1.name.value to get the value of name field.

<html>
<body>

<script>
function ns()
{
var name = document.form1.name.value;
alert(“Welcome: ” + name);
}
</script>

<form name=”form1″>

Enter Name:<input type=”text” name=”name”>

<input type=”button” onclick=”ns()” value=”click here”>

</form>

</body>
</html>

Click here

Share this page :