0

I have following Page with Form Data

<form id="myform" method="post" action="page2.html">
    <input type="hidden" value="1" name="A"
    <input type="submit" value="Submit" />
</form>

When I submit the form, I try to read the form values in Page2.html...I have below code in Java Script.

In the below code, I am trying to read the Posted Value but due to some reasons it always gives null value.

<script>
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    console.log(url);
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var A = getParameterByName('A');
alert(A);
</script>

Please suggest what is wrong in above code

1
  • second parameter in _ var A = getParameterByName('A');_ Commented Feb 21, 2016 at 4:59

2 Answers 2

1

You cannot read post variables using JavaScript, they are handled at server side.

You have to change your form submit method to "get"

<form id="myform" method="get" action="page2.html">
    <input type="hidden" value="1" name="A" />
    <input type="submit" value="Submit" />
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

0

You forgot to add the Html input closing tag.Please correct It.

<input type="hidden" value="1" name="A"/>

1 Comment

Still same issue. No Luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.