Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing values to javascript onClick()

I have a website with some links. when a user clicks on each link it should pass different integer values which I can use in a .js file. I have to make some operations on the basis of these integer values. please help!!!

like image 987
user2043210 Avatar asked Mar 12 '13 08:03

user2043210


People also ask

Can we pass parameter in onClick function?

Your onclick event handler can optionally accept a MouseEventArgs parameter which Blazor will automatically include when it invokes the handler.

How do you pass a value on onClick react?

In order to pass a value as a parameter through the onClick handler we pass in an arrow function which returns a call to the sayHello function. In our example, that argument is a string: 'James': ... return ( <button onClick={() => sayHello('James')}>Greet</button> ); ...

How do you pass two values on onClick?

example: <button onclick="updateById(`id`, `name`)">update</button> function updateById(id, name) { alert(id + name ); ... } Save this answer.

Can you pass a variable to JavaScript?

In Pass by Reference, a function is called by directly passing the reference/address of the variable as the argument. Changing the argument inside the function affects the variable passed from outside the function. In Javascript objects and arrays are passed by reference.


1 Answers

Though this question is most likely to get closed. You can call a function and pass the integer as parameter.

try this

 <a href="#"  onclick="yourFunction('1')">click1</a>
 <a href="#"  onclick="yourFunction('2')">click2</a>

javascript

 function yourFunction(intValue){
   alert(intValue);
}
like image 168
bipen Avatar answered Sep 23 '22 18:09

bipen