Solved

how to pass query string when user click on hyperlink text

Posted on 2004-04-15
13
992 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 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