How to get values from posted html form using javascript -


i have 2 html forms , posting input data 1 html form html form.i want retrieve values of variables posted using form 1 on form 2.

<form name ="form1" id ="form1" method ="post" action = "form2.html>    <input id ="sendtoform2" type ="hidden" value ="send form2"/> </form> 

my question how value of hidden variable sendtoform2 on form 2 once posted form 1 form 2 using javascript.

you can't use post method because plain html page not have http headers html page code , url (with query string).

what can use get instead of post parse query string extract them:

<form name ="form1" id ="form1" method ="get" action = "form2.html>    <input id ="sendtoform2" type ="hidden" value ="send form2"/> </form> 

then in form2.html can use function (from this post on so) parse query string:

function getparameterbyname(name) {     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");     var regex = new regexp("[\\?&]" + name + "=([^&#]*)"),         results = regex.exec(location.search);     return results == null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } 

now (let me use jquery) can access them this:

<form ...>    <input id ="sentfromform1" type ="hidden" value =""/> </form>  </script>     $("#sentfromform1").val(getparameterbyname("sendtoform2")); </script> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -