Jump to content

Javascript Form Help?


XHTMLboy

Recommended Posts

Hello, i need some help quick. I am doing my assignment and it's due in tomorrow. The task is to do a submit button and when clicked the form should return the form data to: website.co.uk/example/register.php ^ I have done that. Than i have to Show how JavaScript can be used to validate the form data (i.e. ensure that the user has completed all the fields) and only return the form data to the server if all the fields have been completed. <-- That is what i need help with. My code at the moment is: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Form - Webpage</title></head><body> <section id="wrapper"> <form action="computerlabs.co.uk/B09051/register.php" method="post"> First Name: <input type="text" /> Last Name: <input type="text" /> <br /> <hr /> Address 1: <input type="text" /> Address 2: <input type="text" /> <br /> <hr /> Address 3: <input type="text" /> Address 4: <input type="text" /> <br /> Post Code: <input type="text" /> <br /> <hr /> Email: <input type="email" /> <br /> <hr /> Please Choose A Username: <input type="text" /> Please Choose A Password: <input type="password" /> <br /> <input type="submit" action="computerlabs.co.uk/B09051/register.php" /> </form> </section></body></html> Thanks for your help guys :D

Link to comment
Share on other sites

In the form, you can put an onsubmit handler that checks if all the fields have a value. If the handler returns true, the form will be submitted, if it returns false then the form will not be submitted. Be sure to check on the server side as well because users can disable Javascript.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...