Hello. I am new to JavaScript and need to make sure that all of the fields in this form are populated before the submission will go through, otherwise a message needs to popup saying which fields are missing information. Can someone please help. My code so far is:
<html>
<head>
<title>Gia's Web Page</title>
<link type="text/css" rel="stylesheet" href="style3.css" >
</head>
<body>
<!-- Comment: Introduction -->
<a name="introduction"></a>
<h1>This is my <b>Individual Programming Assignment #1</b>.</h1>
<br><br>
<!-- Comment: Purpose -->
<h3><i>This page has been developed by Gia.</i></h3>
<br><br>
<img src="tulip.jpg" style="opacity:0.4;filter:alpha(opacity=40)"
onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40" /><img src="tulip2.jpg" style="opacity:0.4;filter:alpha(opacity=40)"
onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40" />
<br><br>
<span id="spnWelcome"></span>
<body onLoad="greetUser()">
<script type="text/javascript">
function greetUser()
{
// Prompt the user for their name
var usersName = prompt("Hi. What is your name?", "");
// Get an object reference to the <span> tag
var welcomeTag = document.getElementById("spnWelcome");
// Create an array to hold month names
var monthNames = new Array();
// Populate array with month names
monthNames[0] = 'January';
monthNames[1] = 'February';
monthNames[2] = 'March';
monthNames[3] = 'April';
monthNames[4] = 'May';
monthNames[5] = 'June';
monthNames[6] = 'July';
monthNames[7] = 'August';
monthNames[8] = 'September';
monthNames[9] = 'October';
monthNames[10] = 'November';
monthNames[11] = 'December';
// Get current date/time
var today = new Date();
// Get the month number. Notice that this time, I am not adding 1 to the month number, since having a zero base monthNames array works
// out perfectly with the fact that getMonth() returns a 0-based month index.
month = today.getMonth();
// Get the day of the month
var day = today.getDate();
// Get the full year
var year = today.getFullYear();
// Format the date in the following format: MonthName day, year
var formattedDate = monthNames[month] + ' ' + day + ', ' + year;
// Replace the content of the <span> tag with a personalized message
welcomeTag.innerHTML = 'Hi ' + usersName + '!!! Welcome to my Website! <br>Today is: ' + formattedDate;
}
</script>
<br><br>
<script type="text/javascript">
function createOrder()
{
coffee=document.forms[0].coffee;
txt="";
for (i=0;i<coffee.length;++ i)
{
if (coffee[i].checked)
{
txt=txt + coffee[i].value + " ";
}
}
document.getElementById("order").value="You ordered a coffee with " + txt + "and options.";
}
function check(whip)
{
document.getElementById("answer").value=whip;
}
function flavor()
{
var mylist=document.getElementById("myList");
document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
}
</script>
</head>
<body>
<p>What would you like to drink?</p>
<form>
<p>
<input type="checkbox" name="drink" value="coffee">coffee<br />
<input type="checkbox" name="drink" value="tea">tea<br />
<p>
<input type="radio" name="browser" onclick="check(this.value)" value="with milk">With Milk<br />
<input type="radio" name="browser" onclick="check(this.value)" value="extra milk">With Extra Milk<br />
<input type="radio" name="browser" onclick="check(this.value)" value="light milk">With Light Milk<br />
<input type="radio" name="browser" onclick="check(this.value)" value="no milk">No Milk<br />
<br />
Your milk preference is: <input type="text" id="answer" size="20">
<p>
What size would you like?: <input type="text" size="20" value="Enter small, medium or large here" />
<p>
Would you like it hot, cold or blended?: <input type="text" size="20" value="Enter hot, cold or blended here" />
<p>
Would you like sugar?: <input type="text" size="20" value="Enter yes or no here" />
<p>
Select your favorite flavor:
<select id="myList" onchange="flavor()">
<option></option>
<option>Vanilla</option>
<option>Mint</option>
<option>Butterscotch</option>
</select>
<p>Your favorite flavor is: <input type="text" id="favorite" size="20"></p>
<p>
<input type="button" onclick="formReset()" value="Reset">
<p>
<input type="button" onclick="createOrder()" value="Submit order">
<br /><br />
<input type="text" id="order" size="50">
</form>
<br><br>
<a href="mailto:my_email@yahoo.com">Send e-mail</a>
</body>
</html>