Saumyaraj
Saumyaraj

Reputation: 1250

Unable to send parameters to servlet on form submit through javascript

I have a HTML form as follows:-

<form name="login" id="login" action="<%=application.getContextPath()%>/GoogleLogin" method="get">
<input type=hidden id="firstName"/>
</form>

I am setting the values of this hidden input type in javascript and submitting the form to servlet as follows:-

    <script>
    document.getElementById("firstName").value="XYZ";
    document.getElementById("login").submit();
    <script>

My form is getting submitted but I am not able to get the request parameter "firstName".

http://localhost:8080/Login/GoogleLogin?

Thank you for your time and consideration.

Upvotes: 3

Views: 1463

Answers (1)

MD Sayem Ahmed
MD Sayem Ahmed

Reputation: 29166

Add a name attribute to the input field -

<input type="hidden" id="firstName" name="firstName" />

then you'll be able to get the request parameter using firstName.

Upvotes: 3

Related Questions