Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  143] [ 4]  / answers: 1 / hits: 28540  / 12 Years ago, mon, december 24, 2012, 12:00:00

I am developing a web application using JSP and Servlet.



I am trying to call javascript function on the click event of hyperlink, and with that I am also passing some parameters to servlet using query string.



<td> <a href=#?id=<%=data[i][0]%>&protID=<%=data[i][1]%>&seqNo=<%=data[i][2]%> onclick=getValues(); >Edit</a></td>


javascript function:



<script>
function getValues()
{
var url = document.URL;
var planID = url.split(=);
var pID = planID[1].split(&);

var remURI = url.split(&);
var protID = remURI[1].split(=);

var s = remURI[2].split(=);

document.getElementById('txtPlanID').value=pID[0];
document.getElementById('txtProtID').value=protID[1];
document.getElementById('txtSeqNo').value=s[1];

//show(block);
return false;
}
</script>


But the problem is that I have to click twice on hyperlink to get desired result.
I think onClick event is executing before sending query string.
Please let me know if there is anything wrong in source code.



Thanks in advance.....


More From » html

 Answers
4
<td> <a href=# onclick=getValues('<%=data[i][0]%>','<%=data[i][1]%>','<%=data[i][2]%>'); >Edit</a></td>


function getValues(pID,protID,eq)
{

document.getElementById('txtPlanID').value=pID;
document.getElementById('txtProtID').value=protID;
document.getElementById('txtSeqNo').value=eq;

//show(block);
return false;


}



simply pass values while calling javascript get use it


[#81244] Saturday, December 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nestorjarettg

Total Points: 451
Total Questions: 108
Total Answers: 108

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;