IndianaGuy Posted December 17, 2016 Share Posted December 17, 2016 (edited) Can I send a value of a buotton to a JavaScript? or the id or anything at all. II don't care if it gets the value/name/or id. I just need a unique identifier telling the function which button was clicked. Thank you <button type="button" value="Value_test" id="id_test" name=" Name_Test" onclick="mySwitch(this)">Click Me!</button> function mySwitch(x){ xVal = document.getElementById(x).value; console.log("var x = " + xVal); { Edited December 17, 2016 by IndianaGuy Link to comment Share on other sites More sharing options...
Ingolme Posted December 17, 2016 Share Posted December 17, 2016 In your code the variable "x" already contains a reference to the button. You can get its value, name or innerHTML. function mySwitch(x){ xVal = x.value; console.log("var x = " + xVal); } Link to comment Share on other sites More sharing options...
IndianaGuy Posted December 18, 2016 Author Share Posted December 18, 2016 Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now