Please send questions to
st10@humboldt.edu .
<html>
<!--
js_form6.html
by: Sharon Tuttle
last modified: 09-12-06
-->
<head>
<title> js_form6 </title>
<script type="text/javascript">
<!--
// function: disp_alert
//
// display a self-descriptive alert popup
function disp_alert(desiredString)
{
alert(desiredString)
}
// function: list_form_elements
//
// display the elements of a particular form
function list_form_elements(aForm)
{
document.write("<li> aForm.elements.length: ",
aForm.elements.length, "</li><br>")
for (var i = 0; i < aForm.elements.length; i++)
{
document.write("<li> aForm.elements[", i,
"].type: ", aForm.elements[i].type, "</li><br>")
}
}
// function: validate
//
// see if <aForm> has filled fields, with the second numeric
function validate(aForm)
{
// note: for a text box, value property contains
// whatever is CURRENTLY typed in that text box
var phrase = aForm.desiredPhrase.value
var quantity = aForm.howMany.value
if ((phrase == "") ||
(phrase === null))
{
alert("Error! please enter a desired phrase.")
// makes this text box the "current"/highlighted
// element
aForm.desiredPhrase.focus()
return false
}
else if ((quantity == "") ||
(quantity === null) ||
(isNaN( Number(quantity) )))
{
alert("Error! please enter a numeric amount.")
aForm.howMany.value = ""
aForm.howMany.focus()
return false
}
// if get here -- OK to submit form
return true
}
// function: confirm_reset
//
// make sure user WANTS to clear form...
function confirm_reset()
{
return confirm("Are you sure you want to clear " +
"the form?")
}
//-->
</script>
</head>
<body>
<h3> js_form6.html </h3>
<h4> (adapted by Sharon Tuttle, last modified 09-12-06) </h4>
<hr>
<form action="http://www.humboldt.edu"
method="get"
name="firstFormWithTextBox"
onsubmit="return validate(this)"
onreset="return confirm_reset()">
<input name="desiredPhrase"
type="text"
size="13"
maxlength="10"
value="type here">
<input name="howMany" type="text" size="5" maxlength="5"
value="0">
<br>
<input type="submit" value="SUBMIT ME">
<input type="reset" value="CLEAR FIELDS">
</form>
<hr>
<form name="buttonsForm">
<input type="button" onclick="disp_alert('from buttonsForm')"
value="Display alert box">
<br>
<input name="quantity" type="text" size="10" maxlength="10">
<br>
<input type="button"
value="Useless button">
</form>
<hr>
<h4> Information about this page's forms: </h4>
<ul>
<script type="text/javascript">
<!--
document.write("<li> This page contains ",
document.forms.length, " forms </li><br>")
document.write("<li> FIRST FORM: </li>")
document.write("<ul><li> document.firstFormWithTextBox.name: ",
document.firstFormWithTextBox.name, "</li><br>")
document.write("<li> document.forms[0].name: ",
document.forms[0].name, "</li><br>")
list_form_elements(document.firstFormWithTextBox)
document.write("</ul>")
document.write("<li> SECOND FORM: </li>")
document.write("<ul><li> document.forms[1].name: ",
document.forms[1].name, "</li><br>")
list_form_elements(document.forms[1])
document.write("</ul>")
//-->
</script>
<noscript>
<li> Your browser does not support JavaScript, or has it disabled;
<br>
please note that, as a result, this page will not work. </li>
</noscript>
</ul>
<hr>
</body>
</html>