Ask Experts Questions for FREE Help !
Ask
    xtazy's Avatar
    xtazy Posts: 3, Reputation: 1
    New Member
     
    #1

    Oct 13, 2003, 10:04 AM
    Validate a form
    Can someone send me the java script codes for validating a form when the user has fill it completely. If evrything is validated and the user clicks on the submit button, a new window should open confirming all entries made on the previous form.
    If the user don't fill everything he won't be able load the confirming page.
    coreybryant's Avatar
    coreybryant Posts: 134, Reputation: 2
    Junior Member
     
    #2

    Oct 14, 2003, 04:38 AM
    Validate a form
    This page should really be helpful:

    http://hotarea.com/fast/display.exe?...alTextBox.html
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #3

    Feb 25, 2004, 07:29 AM
    Validate a form
    What Corey put would work, but I wouldn't say it's 100% helpful. If you have more than one text box on the screen, the error messages are going to be a little useless. Plus it's for clicking on a link, not submitting a form.

    Here's what I would have. Like in Corey's link, you'll need a piece of JavaScript to validate the form input. I don't have time to write out the code, so here are some pointers in the form of comments...

    Code:
    <script language="javascript">
      function validateForm() {
        // Create a string to hold an error messages
        var errorsFound = "";
    
        // Check each form element.  If an error is found,
        // add an error message to the error message
        // variable
        if (someErrorTest) {
          errorsFound += "*  The ??? field was blank.\n";
        }
    
        // Then at the end of the script, check to see if the
        // string you created is still blank.  If it is, there were
        // no errors.
        if (errorsFound == "") {
          // Return true tells the form to move onto the page
          // specified in the action parameter of the form tag
          return true;
        } else {
          // Return false tells the form NOT to move onto the
          // page specified in the action parameter of the form
          //tag
          // Print the error messages to the screen
          alert("Errors Found :\n\n"+ errorsFound);
          return false;
        }
      }
    </script>
    Then when you create your form, use something along the lines of :

    Code:
    <form action="somepage.html" method="post" onsubmit="validateForm()">
    This will call your validate function. If everything went well, true would be return and the form would know that the submit went well, and to move onto the next page. If false was returned, you know there were errors and the page doesn't change.

    I know that's not much help, but it's a starting point. P.s. Sorry about the dodgy code formatting. No idea why it set itself out like that.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Which tax form?f1-opt-h1 [ 1 Answers ]

Hi, I am single and frm india.my status n US stay hv been: f1-5jan-31 dec 2004 f1-1st jan 2005-10 feb 2005 Opt-11 feb 2005-30 sept 2005 h1b visa-1 oct 2005 till date I hv a question about which tax form should I use for tax year 2005 and am I a resident or non-resident alien?also note...

H1B tax form [ 4 Answers ]

January 2005, my H1B was approved and worked for 8 month. Thereafter, I got displaced due to hurricane Katrina and relocated. I transferred my H1B to new employer in a different state. Worked for new employer for 2 month. I've been residing in the US since July 2001. Traveled out of the us twice, 2...

What Tax Form I should use [ 1 Answers ]

Hi, I am from India. I was on OPT for first 3 months then turned to H1B for the rest of the year. I worked for the same company so I have only one W2 form. I also have some stock in my company that I purchased. I also donated some amount for which I can claim tax exemption. Last year I went...

Which Form? [ 3 Answers ]

Hi, I am confused as to which form to fill. My H1B started in Nov 2004 and bfore that I was on OPT. Also, I originally filed my returns for 2004 using the 1040EZ form, and then later realised that I might have had to use th 1040NR-EZ form. If I am right, how do I proceed. Do I use the 1040X...


View more questions Search