Reputation:
I have a HTML form whose action tag redirects to the same page, with appended variables generated by JSP (the variables print existing variables), but when I use the form it only shows the current URL with only the variable from the form, so the other, JSP generated, variables are missing. My (simplified) form looks like this:
<form id="tfnewsort" method="get" action="./index.jsp?categorie=<% out.println(categorie); %>&minprijs=<% out.println(stringminprijs); %>&maxprijs=<% out.println(stringmaxprijs); %>">
<select name="sorteermethode" id="sortselect">
<option value="date_added">
Datum oplopend
</option>
</select>
</form>
As you can see, it should redirect to a URL created by printing some variables and appending it's own variable ("sorteermethode") to the end of the URL. Now, when I actually use it, it redirects to something like 'http://localhost:8080/webshop/index.jsp?sorteermethode=name', essentially ignoring the other variables and replacing it by it's own variable, instead of appending it to the end of the URL. Does anyone know what I'm doing wrong (besides using JSP scriplets) and/or how to solve this?
I would greatly appreciate any help!
Upvotes: 0
Views: 1049
Reputation: 167172
Use it as hidden
input fields, as both the query string and the <form>
's method is also GET
.
<input type="hidden" name="categorie" value="<% out.println(categorie); %>" />
<input type="hidden" name="minprijs" value="<% out.println(stringminprijs); %>" />
<input type="hidden" name="maxprijs" value="<% out.println(stringmaxprijs); %>" />
Upvotes: 0
Reputation: 81
You should add the other variables as hidden input elements. The point of GET is to add all the input values to the querystring, it does not merge them with the current action.
Upvotes: 0
Reputation: 943207
The form data generates a new query string. This replaces the existing one.
If you want to put extra data in it, then put it in hidden input elements instead of the action.
Upvotes: 1