View Full Version : Hidden Text Field and process page help.

07-14-2011, 04:32 AM
I need for the form to do the following:
when age is greater than or equal to 65 enter "yes" in the hidden field
when age is less than 65 enter "no" in the hidden filed
return true

Create a page processAge.htm that
Writes the message on the page
Hi name. At age # you may retire.
Hi name. At age # you are not ready to retire. Get to work.
name is the name entered on the form.
# is the age entered on the form.


<script type="text/javascript">
/* <![CDATA[ */
function validateSubmission() {
var retValue = true;
if (document.forms[0].name.value == "") {
window.alert("You did not fill in one of the following required fields: Name or Age.");
retValue = false;
function checkForNumber(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == true) {
window.alert("You must enter a numeric value!");
return false;
/* ]]> */

<form action="processAge.htm" method="get" onsubmit="makeList(); return validateSubmission(); ">
<table frame="border" rules="cols" >
<td valign="top">
<p>Name<br />
<input type="text" name="name" size="40" /></p>
<p>Age<br />
<input type="text" name="age" size="40" onchange="return checkForNumber(this.value);" /></p>
<p style="text-align: center"><input type="submit" value="Send" /><input type="reset" />
<input type="hidden" name="Retirement" /></p>

Process Page:

<script type="text/javascript">
/* <![CDATA[ */
document.write("<h1>Your form has been submitted!</h1><h2>You entered the following data:</h2>");
var formData = location.search;
formData = formData.substring(1, formData.length);
while (formData.indexOf("+") != -1) {
formData = formData.replace("+", " ");
formData = unescape(formData);
var formArray = formData.split("&");
for (var i=0; i < formArray.length; ++i) {
document.writeln(formArray[i] + "<br />");
/* ]]> */

Thanks for any help!

07-14-2011, 06:14 PM
First off outofcrayons, you have no 'value' set in the hidden field, so you can't change it. The line S/B <input type="hidden" name="Retirement" value="maybe" />.

Next: Your using the $_GET method to send form info. You should send it to a php file for processing not a html file. To make sure your form works start with this php

echo 'the php file<br />';
echo $_GET["name"], '<br />';
echo $_GET["age"], '<br />';
echo $_GET["Retirement"], '<br />';

Lastly Your javascript for checking the form and then submitting it should be one function and should be called from the submit button. Google it.