We help IT Professionals succeed at work.
Get Started

Trying to modify a Jquery form submittal

Last Modified: 2012-05-05
I need to have a form that submits without refreshing, so I used JQuery from a tutorial I found to submit email information that will refer a friend/contact to webcast on our site. Once it is submitted a Thank You message replaces the form. I want to make a button that allows the form to reappear and allow the user to submit another email without refreshing the page. I have attached the code below.
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailToVal = $("#emailTo").val();
		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">You forgot to enter the email address to send to.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {
			$("#emailTo").after('<span class="error">Enter a valid email address to send to.</span>');
			hasError = true;
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">You forgot to enter the email address to send from.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">Enter a valid email address to send from.</span>');
			hasError = true;
		var subjectVal = $("#subject").val();
		if(subjectVal == '') {
			$("#subject").after('<span class="error">You forgot to enter the subject.</span>');
			hasError = true;
		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#name").after('<span class="error">You forgot to enter your name.</span>');
			hasError = true;
		var messageVal = $("#message").val();
		if(messageVal == '') {
			messageVal = " ";
			hasError = true;
		var showlinkVal = $("#showlink").val();
		if(showlinkVal == '') {
			$("#showlink").after('<span class="error">You forgot to enter the show link.</span>');
			hasError = true;
		if(hasError == false) {
			$("#sendEmail li.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
   				{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectVal, name: nameVal, message: messageVal, showlink: showlinkVal },
						$("#sendEmail").slideUp("normal", function() {
							$("#sendEmail").before('<div id="message"><h2>Thank You!</h2><p>Thank you for refering this episode of Industry Today.</p><img id="checkmark" src="images/check.gif" height="48" width="48" /><form action="" method="post" id="referagain"><button type="submit" id="another">&laquo;Refer Another Friend</button></form></div>');
		return false;
	/* New code - This is where I need the help*/
		return false;
	/* End New Code*/

Open in new window

Watch Question
Analyst developer
This problem has been solved!
Unlock 2 Answers and 2 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE