Reputation: 57
I'm completely new to JavaScript and have been trying to figure out how to pass parameters correctly. So far, all my functions have been written without parameters and I can do exactly what I want without parameters, but I'd like to be comfortable using parameters as well.
Let's say that my HTML file has the following button:
<button name="button1"
onclick="myFunction(document.getElementById('form1').
elements.namedItem('text1').value)">Try me</button>
How would I write this function to take this parameter?
function myFunction(???) {
var x = ???;
}
How would I set x to that paramenter?
Thanks
Upvotes: 2
Views: 92
Reputation: 1740
you can do like this:
function myFunction(param)
{
var x = param;
}
Upvotes: 1