Leon Csergity Leon Csergity - 1 year ago 83
HTTP Question

Can't submit arguments in the URL when using a HTTP GET to fetch data from the db

First of all the initial problem was that in the application there is a return button which uses < javascript:history.back() > to return to the previous page. What works just fine in its self.

BUT when clicked throws you to a page that asks you if you want to resubmit your form. This is happening because the previous page uses POST to get some data from the DB and as a safety measure ask you if it would be wise to resubmit the form.

Now everything is clear and understandable here, so i changed the method to GET.
Thinking that would solve everything, but sadly that is not the case.

This is the form in question.

<form accept-charset="utf-8"
method="GET" id="formule">
<table align="center" border="0">
<td><i18n:message>Société</i18n:message> &nbsp;</td>
<td><b><%=ParamLibFacade.getLabelText(ApplicationProperties.getCompany(), Table.COMPANY)%></b></td>
<td><i18n:message>Code produit</i18n:message> &nbsp;</td>
<td><select name="cProd" onChange="validation('cProd')">
<option value="titre"><i18n:message>Sélectionner un produit</i18n:message></option>
i = 0;
while (i < listeProSoc.nbProduit) {
produit = listeProSoc.codeProduit[i];
if (produit.equals(produitorigine)) {
<option selected="selected" value="<%=produit%>"><%=listeProSoc.libProduit[i]%></option>
} else {
<option value="<%=produit%>">
<p align="center"></p>
<input id="modifier" type="hidden" value="1"></input>


It has its action already set. Which is fine. The problem is that when the < onChange > is called in the < select > .

The function looks like as follows:

function validation(item) {
var modifier = document.getElementById("modifier");
var theForm = document.getElementById("formule");

It does not change the action to what is set in this function. It has the needed information for the controller that is needed in the next page, without it the redirect is not done.

And i'm not sure why that might be happening.

Thank you in advance!!!!! And sorry if i'm missing something obvious! I'm just not sure what the problem is here.

Answer Source

Since you update the action, I would do this simply like this :

theForm.action = "../../../S/S/S/<%=CinematiqueProduit.SER_SYNTH_PROD%>"

(but is it necessary ? what other function could submit the form ? If none, just put the action directly in the form)

Then, for the orig attribute, simply add a hidden input, like the modifier one

<input id="modifier" name="modifier" type="hidden" value="1"></input>
<input id="orig" name="orig" type="hidden" value="<%=CinematiqueProduit.ORIG_LISTE%>" />

I have add the name for the modifier input if needed but it was probably not used before...

Using this solution should generate the correct URL for a GET request using the submit function on the form.


If you need to set the action URL dynamicly, update the values of the inputs instead of putting value in the URL.

Using a GET method recreate the attribute, overriding those you would have put at the begin.

This is why you need to use hidden input to store some values. Just updates does to pass some values in the URL. The form will do the rest ;)

document.getElementById("orig").value = "<%=CinematiqueProduit.ORIG_LISTE%>";
var theForm = document.getElementById("formule");
theForm.action = "../../../S/S/S/<%=CinematiqueProduit.SER_SYNTH_PROD%>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download