tags:

views:

92

answers:

2

I have one form of user name and password fields followed by submit button. How do I stay in current page after clicking submit button without reloding page? Any help is appreciated.

A: 

Try tis if you need a sumit button.

<input type="submit" onclick="return false" />

But you may want to use a simple clickable button if you don't wan't to sumbit your form on click... in this case, this should do the trick:

<input type="button" />
gregseth
A: 

There are a couple of options. First of all in the markup for the submit button you can return false:

<input type="submit" onclick="return false;" />

The problem with the approach above is that it will cancel the submit, not sure if that's desired or not. Another approach you can take is to use something like jQuery to do an ajax request.

To do that you'd need to include jQuery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"&gt;&lt;/script&gt;

Then change your submit button to a regular button:

<input type="button" onclick="doAjaxCall();" />

The javascript function doAjaxCall would then be something like:

<script type="text/javascript">
function doAjaxCall() {
    $.ajax({ url: "destinationurl.aspx", success: function(){
        alert('success! insert success javascript code here');
    }});
}
</script>
Brian Hasden