tags:

views:

1637

answers:

5

Hello,

I am not a big web programmer, and have a friend who wants me to help him with something.

He wants to be able to have a form that once it is submitted changes to say something like "Thanks for submitting" and have the form info disappear. He wants it to be easy for anyone to use, so he can give it to various people to use on their sites.

I was thinking I could use javascript to do it, but not really 100% sure. I want to avoid anything that isn't HTML as much as possible so that it will be usable by as many people as possible.

Thanks.

+2  A: 
danieltalsky
Daniel, the thing is this would require the users of the code to all make multiple copies of their pages. It would be ideal if we could use javascript to hide and show different stuff. See, my edit above...
Alex Baranosky
Yeah, I'm working on an edit with a javascript example
danieltalsky
Great !
Alex Baranosky
Thanks, does this code assume that the "successMessage" is set to display: none, at the start?
Alex Baranosky
Ahh crap, yes it does. It assumes a lot of things. Note that this is SERIOUSLY not a functional example. It will do the show/hide but THEN let the form submit. If you wanted to have it do the hide/unhide AFTER the form submitted to itself you'd have to do differently.
danieltalsky
A: 

Does he want a form that will magically submit to any backend (PHP, ASP.NET, JAVA, CGI, etc), or is he targeting some particular platform?

Jason
he has an asp script that will handle the form info
Alex Baranosky
+1  A: 

Try the jquery form plugin. This will achieve what you're after in an elegant way with minimal coding. In addition to this you'll need to download jquery.

This is a javascript solution, however it's safe to assume that everyone is using a javascript capable browser.

Bayard Randel
A: 

The standard way to do this is to submit the form to a different page (submit.php, for example), which provides a new page with the thankyou message. No javascript, no DHTML.

You could use javascript to replace the innerHTML of a huge div containing everything, or remove all the elements, but I'd advise against it.

Phil H
A: 

There's 2 options:

  1. Old school forms: Person clicks submit and form data gets sent server side via GET or POST, the page loads again and displays "Thanks for submitting"

  2. New school javascript AJAX Person clicks submit and javascript submits form data to server side via AJAX and removes the form elements to then add "Thanks for submitting"

Anything else is some hybrid of both these techniques.

Mr Grieves