Solved

how to pass query string when user click on hyperlink text

Posted on 2004-04-15
13
976 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:mvkraju
  • 8
  • 4
13 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 10833004
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
0
 

Expert Comment

by:princeamin
ID: 10833056
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
0
 

Author Comment

by:mvkraju
ID: 10833391
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?
0
 

Author Comment

by:mvkraju
ID: 10834000
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
0
 

Author Comment

by:mvkraju
ID: 10834258
I am increasing points, if it is difficult.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10835293
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mvkraju
ID: 10835721
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.
0
 

Author Comment

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

Thanks
0
 

Author Comment

by:mvkraju
ID: 10835818
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
0
 
LVL 27

Accepted Solution

by:
rrz earned 80 total points
ID: 10837332
Wow! The javascript turned out more complicated than I thought. Since you are using  Struts (as suggested by "princeamin" in his post), maybe this should be done at the server ?  Anyway the javascript was just an idea. Here is what works for me.   rrz

<html>
<head>
<script>
      function addData(){
           var envType = "T";
           if(document.index.envType[1].checked)envType = document.index.envType[1].value;
           if(document.index.envType[2].checked)envType = document.index.envType[2].value;
           document.links[0].href = "/iaInformation/index.do?envType=" + envType;
      }
</script>
</head>
<body>
<a href="#" onclick="addData();" >
0
 
LVL 27

Expert Comment

by:rrz
ID: 10837354
>var envType = "T";
maybe I should have used  
var envType = document.index.envType[0].value;  
0
 

Author Comment

by:mvkraju
ID: 10841277
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
 
0
 

Author Comment

by:mvkraju
ID: 10841288
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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now