Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  103] [ 1]  / answers: 1 / hits: 193171  / 8 Years ago, wed, october 19, 2016, 12:00:00
<input type=button value=mybutton1 onclick=dosomething()>test


The dosomething function evoked when to click the button,how can pass the value of the button mybutton1 into dosomething function as it's parameter ?


More From » javascript

 Answers
7

You can pass the value to the function using this.value, where this points to the button



<input type=button value=mybutton1 onclick=dosomething(this.value)>


And then access that value in the function



function dosomething(val){
console.log(val);
}

[#60342] Monday, October 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryankiah

Total Points: 183
Total Questions: 99
Total Answers: 112

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;