tags:

views:

4473

answers:

4

hi all.

I want to pass a textbox value from source JSP file to the destination JSP file on a href click event withour using javascripts. can anyone help me out in this?

i tried using the following method but iam getting error like "End tag is required"

<a href="/destinationFile.jsp?sDate=<%='+txtDate.value+' %>">

thanks in advance Malathy.L.

A: 
<script type="text/javascript">
   function doPost(){
     form1.submit();
   }
</script>

<form name="form1" method="post" action="page2.jsp">
  <input type="text" name="name"/>
  <a href="javascript:doPost()">Submit</a>
</form>

EDIT:

<%  
out.println("<a href=\"page2.jsp?name='" 
                         + request.getParameter("name") 
                         + "'\">Click Me</a>"); 
%>

<form name="form1" method="post" action="page1.jsp">
      <input type="text" name="name"/>
      <input type="submit" name="cmd" value="Submit"/>
</form>

PS: You may also use jsp action - <jsp:forward/>

adatapost
hi.. i need to pass the value without using Java script. Along with textbox value i will be passing 4 more parameters which are not the controls value but the local variable values. so i think "form.submit" will not be helpfull. can you suggest me any other possibilities.thanks in advance Malathy.L.
Malathy
A: 

You have to close the tag:

<a href="/destinationFile.jsp?sDate=<%='+txtDate.value+' %>" />

Then, in the destinationFile.jsp, you can access the value by using request.getParameter("sDate").

JG
A: 

You are mixing server side and client side coding.
<%='+txtDate.value+' %> is not correct.
Anything between <% and %> or <%= and %> is serverside ("java") coding and will be executed on the server.

txtDate should be a textbox on the client side. You want to pass the values in the textbox to another page. This entire operation is a client side operation and should NOT be inside <% %>

If you want value entered by the client, you need javascript to pass the parameters in the query string, and for this you need java script.

You can submit the entire form, but you need javascript at least to submit the form.

Nivas
A: 

Just use a <form> in combination with some CSS to style the button to make it look like a link:

<form action="destination.jsp">
    <input name="txtDate">
    <input type="submit" value="go to destination.jsp" class="link">
</form>

with for example this css:

input[type=submit].link {
    background: transparent;
    border: 0;
    color: blue;
    text-decoration: underline;
    overflow: visible;
    cursor: pointer;
}
BalusC