views:

148

answers:

2

Hello,

Can someone help me with this problem: I have a table in a jsp page, with the text in one column being hyperlinks. Whenever anyone of these hyperlinks is clicked the whole table should refresh and repopulate based on the value of the hyperlink clicked. My problem is currently when the hyperlink is clicked the page refreshes with an empty table. I have the following line of HTML code for performing this in my jsp page:

<TD><A href="http://localhost:8080/pmweb/gui.jsp" onclick="getResults(param)">hyperlinktext</A></TD>;

Below is my getResults function in javascript in the same JSP page:

<script type="text/javascript">
var httpRequest; 

function getResults(param) {

    var url = "http://localhost:8080/pmweb/api/GetResultsByParam?param=" + param;

    httpRequest = new XMLHttpRequest();  

    httpRequest.open("GET", url, true);

    httpRequest.onreadystatechange = function() {processRequest(); } ;

    httpRequest.send(null);   
}

I have verified that the getResults function above is working fine itself. When I debugged it I noticed that this getResults function is not entered when the hyperlink is clicked. Anyone know how to get the hyperlink calling the javascript function properly? Thanks very much in advance!

+1  A: 

when u call

<TD><A href="http://localhost:8080/pmweb/gui.jsp" onclick="getResults(param)">hyperlinktext</A></TD>;

param is undeclared in getResults(param).. pass some value instead.

like,

<TD><A href="http://localhost:8080/pmweb/gui.jsp" onclick="getResults('name')">hyperlinktext</A></TD>;
echo
Hi guys,Thanks for the replies. Amarghosh when you say return false from the getResults method do you mean adding the line "return false;" to the end of the method? I've tried that and it didn't work. I got the same results. Please note that I have also slightly modified the method and variable names in the code I supplied above. I am actually parsing in an actual value as parameter for "param".Cheers!
liz
I have also tried coding:<TD><A href="http://localhost:8080/pmweb/gui.jsp" onclick="getResults('name'); return false">hyperlinktext</A></TD>;This didn't work either ...
liz
It won't redirect to the url : "localhost:8080/pmweb/gui.jsp" (because of the `return false` statement!! ).. instead the getResults javascript function will be called. try having alert("Getting In"); as the very first line in ur function and try.. `function getResults(value) { alert("Getting In"); ... ... }`
echo
+2  A: 

Clicking on an anchor will take the user to the page specified in its href attribute. You must return false from the click handler to prevent this.

hyperlinktext

And return false from the getResults method.

Also, as raj noted, make sure that param is defined.

Amarghosh