Reputation: 45
There is a function tool which have 2 parameters. I have to change the value of the parameter a(1 to 2) and b(2 to 3). How can I change this? Please give your valuable answer.
<html>
<head>
<script>
function tool(a,b) {
}
</script> </head>
<body>
<a href="javascript:tool(1,2)" name ="link" title="before click">click here</a>
</body>
</html>
Upvotes: 1
Views: 105
Reputation: 15461
You can add an event listener:
function tool(a, b) {
console.log(a, b);
}
document.getElementById("link").addEventListener('click',
function(e) {
e.preventDefault();
tool(2, 3);
});
<a href="javascript:tool(1,2)" name="link" id="link" title="before click">click here</a>
Upvotes: 0
Reputation: 2138
Use what you want to do. But your question is not clear. As I understand I am giving your answer
Answer 1
function tool(a, b) {
console.log(a, b);
document.getElementById('link').href='javascript:tool(2, 3);';
}
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
Answer 2
function tool(a, b) {
console.log(a, b);
document.getElementById('link').href='javascript:tool('+(Number(a)+1)+', '+(Number(b)+1)+');';
}
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
Upvotes: 1
Reputation: 386560
You could update the href
property of the anchor node.
function tool(a, b) {
console.log(a, b);
}
document.getElementById('link').href='javascript:tool(2, 3);';
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
Upvotes: 1