Retrieving Http Get url from a html form via jquery

forms, html, jquery

Solution

Here is the solution:

HTML:

<form id="frm" method="POST" action='someaction'>
  <input type='text' id='txt1' value='Hello'/>
  <input type='text' id='txt2' value='World'/>
</form>

Your GET URL is: <div id="url"></div>

Javascript (using jQuery):

var url = $("#frm").attr("action") + "?";
var urlElements = [];
$("#frm").children().each(function(){
    urlElements.push($(this).attr("id") + "=" + $(this).attr("value"));
});
urlElements = urlElements.join("&");
url += urlElements;
$("#url").html(url);

You can test it here: http://jsfiddle.net/3S9db/

Hope this help :)

Problem

Is there any way to retrieve a from url with out submitting it, some how simulating a form submission via HTTP Get. I mean for this example ``` <from id="frm" method="POST" action='someaction'> <input type='text' id='txt1' value='Hello'/> <form> ``` I want to get bellow string without submitting form ``` someaction?txt1=Hello ```

Original source