Ajay Nair
Ajay Nair

Reputation: 1867

Prevent page reload on form submit

I am trying to submit a form using get method but I dont want the form to refresh or rather when it reloads I want to maintain the data. There seems to be lot of questions on similar lines but none that I tried helped. I am posting my code here:

<script type="text/javascript">
 function formSubmit()
 {
     document.getElementById('form1').submit();
     return false;
 }
</script>


<form id = "form1" method = "GET">
    <br> Query:  <input name="query" id="query" type="text" size="50" value="">
   <input type="button" name="search" value="Get News" onclick = "formSubmit()">
</form>

I am using python on the server side.

Thanks

Upvotes: 0

Views: 790

Answers (1)

Kevin Bowersox
Kevin Bowersox

Reputation: 94469

The statement:

    I am trying to submit a form using get method but I dont want the form  to 
refresh or rather when it reloads I want to maintain the data.

Implies to me that your end goal requires AJAX or at least some passing of data to the server and back. You will not be able to retain scope within Javascript over a page refresh without the use of something like cookies or passing data to/from the server. Having said that these are more akin to secondary storage mechanisms while you want to retain scope (or primary storage). To do this I would recommend AJAX.

Upvotes: 1

Related Questions