Results 1 to 12 of 12

Thread: Javascript - Submit form and validation

  1. #1
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Javascript - Submit form and validation

    I need help with some JavaScript. The purpose of it is to order tickets from the form where the tickets are fixed price of £30.

    It needs validation on it so that it know that the user hasn't entered a first name, surname and e-mail. and will times the £30 cost by the amount the they have selected in the drop down box.



    This is what I'm working with.

    the form id's are:

    FirstName
    Surname
    Quantity
    e-mail
    and the button is submit

  2. #2
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb

    Re: Javascript - Submit form and validation

    Is this a homework assignment?

    Check out W3Schools Javascript Form Validation Tutorial

  3. #3
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    One of my college assignments and thanks i'll take a look at it

  4. #4
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    So i've got a bit further after taking a break i now got my validation down and working.

    Problem i have now is that when i select the amount of tickets i want and press submit it suppose to take me to a new page saying my total order is and so on? This is what i got any ideas?

    PHP Code:
     else { var totreq document.getElementsById("Amount").value;
      var 
    cost=30;
      var 
    frmreq cost totreq;
      
    document.write(" Thank you for your request.");
      
    document.write(" you have requested "totreq +" items .");
      
    document.write(" total cost is £" frmreq);
      
    document.write(" Please return to the website");
          }
    }
     } 

  5. #5
    Senior Member
    Join Date
    Jun 2012
    Posts
    2,401
    Thanks
    87
    Thanked
    151 times in 145 posts
    • Willzzz's system
      • Motherboard:
      • Gigabyte
      • CPU:
      • 4670K
      • PSU:
      • FD Newton R3 600W
      • Case:
      • Corsair 350D

    Re: Javascript - Submit form and validation

    Why is totreq coming from a a document element? Shouldn't this be coming from the form that was submitted on the previous page?

    Is the form a GET or POST?

  6. #6
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    the form is a post

  7. #7
    Senior Member
    Join Date
    Jun 2012
    Posts
    2,401
    Thanks
    87
    Thanked
    151 times in 145 posts
    • Willzzz's system
      • Motherboard:
      • Gigabyte
      • CPU:
      • 4670K
      • PSU:
      • FD Newton R3 600W
      • Case:
      • Corsair 350D

    Re: Javascript - Submit form and validation


  8. #8
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    the language i'm using is JavaScript not PHP i just posted the JavaScript in the PHP Code to make it easier.

  9. #9
    Senior Member
    Join Date
    Jun 2012
    Posts
    2,401
    Thanks
    87
    Thanked
    151 times in 145 posts
    • Willzzz's system
      • Motherboard:
      • Gigabyte
      • CPU:
      • 4670K
      • PSU:
      • FD Newton R3 600W
      • Case:
      • Corsair 350D

    Re: Javascript - Submit form and validation

    Oh.

    Well in that case I imagine that you are supposed to process the information on the same page in that case.

    The 'submit' isn't really a submit, it's a just a button that points to a javascript function.

  10. Received thanks from:

    Anti-Uber182 (21-04-2013)

  11. #10
    Registered+
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    2
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    Alright thanks i'll play about a bit and see what happens =)

  12. #11
    Registered+
    Join Date
    Dec 2013
    Posts
    19
    Thanks
    0
    Thanked
    1 time in 1 post

    Re: Javascript - Submit form and validation

    You could use built in HTML 5 validation and do the rest in Javascript.

  13. #12
    Registered+
    Join Date
    Jan 2014
    Posts
    21
    Thanks
    0
    Thanked
    0 times in 0 posts

    Re: Javascript - Submit form and validation

    jQuery is great for validation stuff like that, although you may not be allowed to use it for a college assignment.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •