• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

jquery reset form help

hello
i am trying to find a way to reset a div in a form. the div is #message and the code i am using at the moment is clearing the fields but not the message. if someone could show me how to do this i would be grateful as i need to find a solution quickly. many thanks
JQUERY CODE
===============================

// Feedback form

jQuery(document).ready( function() {

  $("#form").hide();

});

			
  function feedbacknew() 
{    
	$("#form").dialog(
	{
	    autoOpen: false,
	    resizable: false,
	    modal: true,
		show: 'slide',
	    title: 'Submit a feedback request',
	    width: 460,
	    height: 490    		
	});
	
	$('#submit').click(function () 
	{
	    
	    var name = $('.uname').val();
		var email = $('.email').val();
		var position = $('.position').val();
		var feedback = $('.feedback').val();
	    var data = 'uname=' + name+email+position+feedback;
	    $.ajax(
	    {
		type: "POST",
		url: "feedback.php",
		data: data,
		success: function (data) {
			$("#feedback").get(0).reset();
			$('#message').html(data);
			$("#flex1").flexReload();
				
		    
		} 
	    });
	    return false;
		
	});
        
	$("#form").dialog('open');
	
}

HTML FORM
================================================

// Feedback form
<div id="form" style="display:none;">
  <form method="post" id="feedback" class="webform" name="feedback">
    
		
		<label for="company">Company</label>
		<select name="company">
		  <option SELECTED VALUE="">Select an option</option>
		  <option value="Technical">Technical</option>
		  <option value="Database">Database</option>
		  <option value="Error">Error</option>
		  <option value="Other">Other</option>
		</select>
		<label for="name">Full Name:</label>
		<input id="uname" name="uname"  type="text" class="text ui-widget-content ui-corner-all inputbox uname" value="<?php echo $_SESSION['kt_name_usr']; ?>" />
		<label for="email">Email address:</label>
		<input id="email" name="email" type="text" class="text ui-widget-content ui-corner-all inputbox email" value="<?php echo $_SESSION['kt_email_usr']; ?>"/>
		<label for="position">Position:</label>
		<input id="Position" name="Position" type="text" class="text ui-widget-content ui-corner-all inputbox position" />
		<label for="Feedback">Feedback:</label>
		<textarea name="Feedback" cols="25" rows="3" type="text" class="text ui-widget-content ui-corner-all inputbox feedback" />Please make sure that any error messages or numbers are listed here.</textarea><br />
	
   	 	<button id="submit" class="submit">Submit</button>
		<div id="message"></div>
  </form>
</div>

Open in new window

0
peter_coop
Asked:
peter_coop
  • 7
  • 5
1 Solution
 
Gurvinder Pal SinghCommented:
so, you are trying to say that this line
$('#message').html(data);

is not setting the data correctly to the div with id message?

can you alert the message to see what is response coming?
0
 
peter_coopAuthor Commented:
@gurvinder372
hello. the message is appearing ok but when i close the form the message is still there when i reopen. i need a way to reset the #message when the form closes. thanks
0
 
Gurvinder Pal SinghCommented:
how do you close the form?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
peter_coopAuthor Commented:
by clicking the X in the top right part of the dialog window. thanks
0
 
Gurvinder Pal SinghCommented:
you need to capture onbeforeclose and clear that div
http://docs.jquery.com/UI/Dialog#event-beforeClose

$("#message").html("");
0
 
peter_coopAuthor Commented:
how that relate to my code please. thanks
0
 
Gurvinder Pal SinghCommented:
apparently you are using the jquery modal dialog plugin, and no where do i see that you are capturing the click on that close button at the right top. You have to capture that event to clear the message
0
 
peter_coopAuthor Commented:
i am new to jquery and would be grateful if you could help with this? i would be willing to raise the points. thanks
0
 
Gurvinder Pal SinghCommented:
all you have to do is check the example in the link that i shared
0
 
peter_coopAuthor Commented:
i did that bit do not understand it. for example, from the code

$( ".selector" ).dialog({
   beforeClose: function(event, ui) { ... }
});

what is event, ui and what goes in between {...}? thanks
0
 
peter_coopAuthor Commented:
got it. so you use like this:

beforeclose: function(event, ui) { $("#message").html(""); }
0
 
peter_coopAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now