Reputation: 1
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!
Upvotes: 0
Views: 1813
Reputation: 3811
When you 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:
...
<TD><A href="http://localhost:8080/pmweb/gui.jsp"
onclick="getResults('name')">hyperlinktext</A></TD>;
Upvotes: 1
Reputation: 59451
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.
Upvotes: 2