Solved

how to pass query string when user click on hyperlink text

Posted on 2004-04-15
13
962 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I am increasing points, if it is difficult.
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mvkraju
Comment Utility
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
Comment Utility
rrz... i could see the follwong URL in my browser
http://localhost:9080/iaInformation/index.do?envType=undefined

Thanks
0
 

Author Comment

by:mvkraju
Comment Utility
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
Comment Utility
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
Comment Utility
>var envType = "T";
maybe I should have used  
var envType = document.index.envType[0].value;  
0
 

Author Comment

by:mvkraju
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

11 Experts available now in Live!

Get 1:1 Help Now