Professional Documents
Culture Documents
191202C0058 Exp7
191202C0058 Exp7
191202C0058 Exp7
Experiment No: 7
Aim Create a webpage to implement form events. Part 1
Practical Significance:
A JavaScript executes in response to an event that occurs while a form is displayed on the
screen. An event is something the user does to the form, such as clicking a button, selecting a
radio button, or moving the cursor away from an element on the form. The browser also fires
events when the page finishes loading from the server.
The default event for the Page object is Load event. Similarly, every control
has a default event. For example, default event for the button control is the
Click event.
192020058
ANS: - The 'with' statement adds the given object to the head of this scope
chain during the evaluation of its statement body. If an unqualified name used
in the body matches a property in the scope chain, then the name is bound to
the property and the object containing the property. Otherwise a
ReferenceError is thrown.
Exercise:
Code
<html>
<body>
<html>
<script type="text/javascript">
function modifyList(x)
{
with(document.forms.myform)
{
if(x ==1)
{
optionList[0].text="Kiwi";
optionList[0].value=1;
optionList[1].text="Pine-Apple ";
optionList[1].value=2;
optionList[2].text="Apple";
optionList[2].value=3;
}
if(x ==2)
{
optionList[0].text="Tomato";
optionList[0].value=1;
optionList[1].text="Onion ";
optionList[1].value=2;
optionList[2].text="Cabbage ";
optionList[2].value=3;
}
}
}
192020058
Client-Side Scripting (Semester V)
57
</script>
</head>
</body>
<form name="myform" action=" " method="post">
<select name="optionList" size="3">
<option value=1>Kiwi
<option value=1>Pine-Apple
<option value=1>Apple
</select>
<br>
<input type="radio" name="grp1" value=1 checked="true"
onclick="modifyList(this.value)"> Fruits
<input type="radio" name="grp1" value=2 onclick="modifyList(this.value)">
Vegitables
</form>
</body>
</html>
Output: -
Code: -
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Get Email ID</button><p
id="demo"></p><script>
function myFunction() {
192020058
var fname = prompt("Please enter your name");
var lname = prompt("Please enter your name");
document.getElementById("demo").innerHTML =
"Your Email Id is " + fname + lname +"@gmail.com";
}
</script></body>
</html>
Output : -
Conclusion:
Hence, we learnt to create a webpage to implement form event like option list.
192020058