Link to home
Start Free TrialLog in
Avatar of mvkraju
mvkraju

asked on

how to pass query string when user click on hyperlink text

Hi,

In my JSP page i have hyper text link. Below that link i will have 3 radio buttons. When user click on the hyper link i want pass the value of selected radio button as a query sting with the URL i mention at <a href="url"> tag.

Here is my code but it's not working, i am getting envType value as null

<BODY>
<%
    String envtype = request.getParameter("envType");
%>
<TABLE width=600 BORDER=0>

<TR>
      <TD><a href="/iaInformation/index.do?envType=<%=envtype%>" ><bean:message key="mwr.link.msg.whows.rpt" /></a></TD>
</TR>

<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="T" checked>Test Environment (T01, T02, T03, T04)</TD>
</TR>
<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="Q" >QA Environment (Q01)</TD>
</TR>
<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="P" >Production Environment (P01)</TD>
</TR>
</TABLE>

</BODY>

Please correct me if i am doing wrong.
I appreciate ur help!

Thanks
Avatar of rrz
rrz
Flag of United States of America image

You could use a HTML form to submit data to server. Or maybe you could use JavaScript to create the URL.

>Please correct me if i am doing wrong.  
You are trying to use JSP on the client side.  JSP is at the server and JavaScript is in the browser.
rrz
Avatar of princeamin
princeamin

For this to work, you need to have /iaInformation/index.do defined in your struts config and working.

<BODY>
<%
    String envtype = request.getParameter("envType");
%>
<TABLE width=600 BORDER=0>
<html:form action="/iaInformation/index.do" method="GET" >
<TR>
     <TD>
<bean:message key="mwr.link.msg.whows.rpt" /></a></TD>
</TR>

<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="T" checked>Test Environment (T01, T02, T03, T04)</TD>
</TR>
<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="Q" >QA Environment (Q01)</TD>
</TR>
<TR>
    <TD class='normal'><input TYPE="radio" NAME="envType" VALUE="P" >Production Environment (P01)</TD>
</TR>
</TABLE>
</html:form>
</BODY
Avatar of mvkraju

ASKER

In my example i mentioned only one hyperlink. But actually i have 2 hyperlinks, for the 2 URLs i want to pass this query string.

princeamin, in that case how does it work?
Avatar of mvkraju

ASKER

If it is not possible this way.
Can i do it using javascript?
but i have no idea how to assign a value  which i get it from JS?

Please give me some suggestions!!!

Thanks
Avatar of mvkraju

ASKER

I am increasing points, if it is difficult.
instead of
><a href="/iaInformation/index.do?envType=<%=envtype%>" ><bean:message key="mwr.link.msg.whows.rpt" /></a>
you could use something like  
><a href="#" onclick="this.href = '/iaInformation/index.do?envType=' + document.formname.envType.value;"><bean:message key="mwr.link.msg.whows.rpt" /></a>  
I did not check my javascript code. You might have change the way I access envType's value.  rrz
Avatar of mvkraju

ASKER

rrz
when i print the envType value in the servlet.
it prints envType value as 'undefined'.
am i mising anything else?
i did exactly as you said.
Avatar of mvkraju

ASKER

rrz... i could see the follwong URL in my browser
http://localhost:9080/iaInformation/index.do?envType=undefined

Thanks
Avatar of mvkraju

ASKER

here is my code
<a href="#" onclick="this.href='/iaInformation/index.do?envType='+document.index.envType.value;" ><bean:message key="mwr.link.msg.whows.rpt" /></a>

am i doing anything wrong.
my form name is index
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>var envType = "T";
maybe I should have used  
var envType = document.index.envType[0].value;  
Avatar of mvkraju

ASKER

rrz.. it seams javascript is working fine. It's picking up right envType value.
But some how when i click on the link, it's not calling /iaInformation/index.do link.
I guess there is some thing wrong in the following statement

document.links[0].href
 
Avatar of mvkraju

ASKER

sorry rrz...
It's working fine. Actually i have links in my page, so when i changed

document.links[0].href  to document.links[1].href
it's working fine.

Thanks