Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Check whether form has been submitted

I want to check if a HTML form has been submitted and then execute a function. I don't want to check if the form button is clicked, but on the server side, but when it's really submitted to the server. The html submits a form that is not on the same website and I don't own the other website (action="http://someurlIdontown.com") so I can't check it on the server. I only want to use javascript/jquery. Does anybody know how to do that?

1 Answer

You can't use normal JS or jQuery to test something on the server side. It's a client-side library. You can write JS server side but I see it's pointless in this case.

What service are you using to send forms? Exactly what are you trying to do? You can always listen for a returned URL from a form, as it surely returns something when you submit it, right?

Thanks for your reply Paul. I'm doing this project for my school and what I want to accomplish is a app that shows your
schedule for the week. The website in not responsive and we want to add some features. I load the schedule in an iframe. I only want to use javascript because I want to use phonegap and it doesn't allow PHP or other languages. To load the schedule properly on the website you have to "post" the date first and "get" the student id afterwards. I don't know why it works like that but if you submit them right afterwards eachother it will not always work because the student id can get submitted to the server first. I can set a timeout but that is not the right way and it still can get wrong. The url is: http://zermelo.dominicuscollege.nl/ . Some idea?

Hmmm, I see. That is somewhat tricky.

The easiest way to do this if you had total control is to have the server receiving the form ping a webhook you've set up when it receives an email. I'm guessing this is not possible for you as you don't control the server being submitted to.

I'm assuming your get is returning some sort of URL, right? I'd think you can listen for this URL with AJAX in the iframe and when you receive it, then do your JS action?

I've searched around Stack Exchange and it doesn't seem like anything quite matches your query exactly, so perhaps you should try asking on Stack Exchange.

Thanks again Paul. I don't know any ajax so I think I'll ask how to listen for the URL with ajax on Stack Overflow then. Thank you for pointing me in the right direction.