0

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

Edited by calebcook: n/a

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by bloodbender
0

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.

0

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.

0

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.)

0

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.

Edited by Taywin: n/a

0

Try this:

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

although that won't give your use m

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.