Hi. I'm trying to make a script which submits the form without refreshing the page. Also, I'd like to have it submit onkeyup.
I can't figure out how to do that.

Can anyone help me?

My code is

<script type="text/javascript">
	$(document).ready(function(){
	
    	var $form = $( '#myform' ),
        url = $form.attr( 'action' );

		$("#myform").validate({
			submitHandler: function(form) {
				
				var rData = $("#myform").serialize();
				
				$.post(url, rData, function(data) {
					$('#results').html(data);
				});
			}
		});
	});
	</script>

Thanks

Is it throwing an any errors?

No. I can submit/display if I click on the submit button (or hit enter), but if I use onkeyup="document.myform.submit();" it submits the form and reloads the page.

I'm not familiar with the validate plugin. But, maybe, instead of using onkeyup="document.myform.submit();" you can use something like this:

$(function()
	{
		$(document).keyup(function(evt)
		{
			if ( evt.keyCode == 13 ) // Enter
			{
				$("#myForm").validate();
			}
		});
	});

Hope it helps.

Hmm. Doesn't work. (and I dont want the user to have to hit anything. I want it to automatically submit when they've typed something.)

If you do the normal submit, the page will reload. What you need is Ajax part to do the submission for you, so that your page will not reload but only a portion of what you want will be reloaded.

I'm not familiar with JQuery to use Ajax. You may need to search for JQuery and Ajax to answer your question. I can do it in pure JavaScript though.

PS: If you are going to use Ajax, you need a server to return the request.

Try this:

$("input#xxxxx").change(function(){
    // Do validation here
    // If validation passes, submit
});

although that won't give your use m

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.