Reputation: 4000
<html:link href="DemoAction.do?method=val1¶m1=val2">DEMO</html:link>
How can i pass val1 and val2 from javascript ?
Upvotes: 0
Views: 417
Reputation: 4020
Add styleId="myLink"
to the <html:link>
in order to query the element with JavaScript.
Then you can do the following in JS:
var val1 = "newval1", val2 = "newval2";
// Option 1: Set the href attribute regardless of its current value
var link = document.getElementById("myLink");
link.setAttribute("href", "DemoAction.do?method="+val1+"¶m1="+val2);
// Option 2: Set the href attribute depending on its current value
var link = document.getElementById("myLink"),
hrefParts = link.getAttribute("href").split("?");
link.setAttribute("href", hrefParts[0]+"?method="+val1+"¶m1="+val2);
Upvotes: 2