faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

55 of 136 people (40%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Can I let a form submission replace the previous url as with location.replace()?
Can you give an example of submitting a form (via POST) and replacing a current URL in the history?

Jul 7th, 2005 00:53
Martin Honnen, eric sho, Tomaz Bartol,


There is no method to submit a FORM and let it replace the previous url 
in the history. If your FORM submission is a post request meaning it 
has attribute METHOD="post" you cannot achieve this submission with 
location.replace. If your FORM submission however is a get request 
(METHOD="get") you can construct the query string on your own and then 
use
  location.replace(
   'formAction?field1=value1&field2=value2&field3=value3'
  );
Constructing the query string requires you to loop through the form 
elements and collect the values.