Using Notepad++, copy the code presented in Listing 26.2, "A Form That Displays Data in a Pop-Up Window," in the subsection "Displaying Data From a Form" in the section "Accessing Form Elements With JavaScript" in Ch. 26, "Working with Web-Based Forms of Sams Teach Yourself HTML, CSS and JavaScript All In One. Save the file using the name Week4ValidationExample.html. Test your code and debug as necessary.
Change the name of the display() function to myDisplay() where my is your first name. For example, if your first name were Sam, your display function would be SamDisplay(). Test your code and debug as necessary.
Change the width and height of the pop-up window in which you have set the feedback to appear as 250 and 400, respectively. Test your code and debug as necessary.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Display Example</title>
<script type="text/javascript">
function display() {
dispWin =
window.open('','NewWin','toolbar=no,status=no,width=300,height=200')
message = "<ul><li>NAME:" +
document.form1.name.value;
message += "<li>ADDRESS:" +
document.form1.address.value;
message += "<li>PHONE:" +
document.form1.phone.value;
message += "</ul>";
dispWin.document.write(message);
}
</script>
</head>
<body>
<h1>Form Display Example</h1>
<p>Enter the following information. When you
press the Display button, the data you entered will be displayed in
a pop-up.</p>
<form name="form1" method="get" action="">
<p>NAME: <input type="text" name="name"
size="50" /></p>
<p>ADDRESS: <input type="text" name="address"
size="50" /></p>
<p>PHONE: <input type="text" name="phone"
size="50" /></p>
<p><input type="button" value="Display"
onclick="display();" /></p>
</form>
</body>
</html>
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new web page with name "Week4ValidationExample.html" is created, which contains following code.
Week4ValidationExample.html :
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>Form Display Example</title>
<!-- <script> is used for javascript -->
<script type="text/javascript">
//function
function ViratDisplay() {
dispWin = window.open('','NewWin','toolbar=no,status=no,width=250,height=400')
message = "<ul><li>NAME:" + document.form1.name.value;
message += "<li>ADDRESS:" + document.form1.address.value;
message += "<li>PHONE:" + document.form1.phone.value;
message += "</ul>";
dispWin.document.write(message);
}
</script>
</head>
<body>
<h1>Form Display Example</h1>
<p>Enter the following information. When you press the Display button, the data you entered will be displayed in a pop-up.</p>
<form name="form1" method="get" action="">
<p>NAME: <input type="text" name="name" size="50" /></p>
<p>ADDRESS: <input type="text" name="address" size="50" /></p>
<p>PHONE: <input type="text" name="phone" size="50" /></p>
<p><input type="button" value="Display" onclick="ViratDisplay();" /></p>
</form>
</body>
</html>
======================================================
Output : Open web page Week4ValidationExample.html in the browser and will get the screen as shown below
Screen 1 :Week4ValidationExample.html
Screen 2 :Screen showing pop up window
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Get Answers For Free
Most questions answered within 1 hours.