?
Solved

how to pass query string when user click on hyperlink text

Posted on 2004-04-15
13
Medium Priority
?
1,019 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
13 Comments
 
LVL 28

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 28

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 28

Accepted Solution

by:
rrz earned 320 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 28

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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