Parameters with Javascript

Asked

Viewed 643 times

2

On the server, I don’t 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 parameter.

In html I put javascript to take the parameter. Now I don’t 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 one. But I don’t 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 form. Can anyone help me?

  • You can better explain this behavior you describe? index.html and the basis of the board is often the same, ie dominio.com will lead to the same dominio.com/index.html.

  • There is a Servlet that sends the parameters. For example, Name. Only it passes to an html. I have no way to change this path. I’d like to take this parameter and move on to a jsp. But I can’t find a solution to take the parameter in HTML E pass to the next, in case a JSP.

1 answer

1

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

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

Add an ID to your form:

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

And at the end of the page:

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

Or also, using jQuery:

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

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

  • It worked sending the parameter, but it is sending, instead of the person’s name, + Querystring('Name'). How do I pass the parameter to the form, in case the Querystring ?

  • @Gilberto If what you want is to pass on what is typed on input, just clean and let the value as value="". It will pick up only what was filled by the user.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.