Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Hidden Text Field and process page help.

    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.
    or
    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.

    Java:
    Code:
    <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;
        }
    } 
    /* ]]> */
    </script>
    Body:
    Code:
    <form action="processAge.htm" method="get" onsubmit="makeList(); return validateSubmission(); ">
    <table frame="border" rules="cols" >
    <tr>
    <td valign="top">
    <h2>Retirement</h2>
    <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>
    </td></tr>
    </table>
    </form>
    Process Page:
    Code:
    <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 />");
    }
    /* ]]> */
    </script>
    Thanks for any help!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    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
    Code:
    <?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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •