Parameters with Javascript

2

On the server, I do not know why, when accessing the site, it goes through a index.html before going to the main page. It turns out that before there is a servlet with some data as a parameter.

In the html I put the javascript to get the parameter. Now I do not know how to send to the main page. I tried to create an index that "invents" a form with the hidden fields and sends the data to the main. But I do not know how to send this data.

<script>

function QueryString(variavel){
   var variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&;")
   var nvar
   if(variaveis!=""){
      var qs=[ ]
      for(var i=0;i<variaveis.length;i++){
         nvar=variaveis[i].split("=")
         qs[nvar[0]]=unescape(nvar[1])
      }
      return qs[variavel]
   }
   return null
}

</script>

<script
<form name="acesso" method="post" action="Principal.jsp">
<input type="hidden" name="Nome" value="+ QueryString('Nome')"


<input type="hidden" name="redirect" value="Principal.jsp">

The problem is in the value of the form. Can anyone help me?

    
asked by anonymous 17.03.2015 / 20:04

1 answer

1

Your code has some errors like the lack of finalization of the <script> tag above the form , and also the lack of completion of the input tag beneath it.

Taking into account that these errors are only by typing the question and your input already has the desired value, what you can do is: at the end of the page force an automatic submission of form via javascript , for example ...

Add an ID to your form :

<form id="formulario" name="acesso" method="post" action="principal.jsp">...</form>

And to the bottom of the page:

<script>
document.getElementById('formulario').submit();
</script>

Or, using jQuery:

<script>
$('#formulario').submit();
</script>

But remembering that forcing the submission of the form, if your form has a validation function in onSubmit , it will not validate.

    
19.03.2015 / 19:58