Reputation: 877
I want to use an input value as a parameter of my "doubleSize" function passing through onclick method.
<!DOCTYPE html>
<html>
<head>
<script>
function doubleSize(x)
{
....//some code
}
</script>
</head>
<body>
<p> Give a number :
<input id="inpt" type="text"></p>
<button id="but" type="button" onclick="doubleSize('????')" >click me!</button>
<div><span id="result"></span>
</div>
</body>
</html>
Upvotes: 3
Views: 121
Reputation: 1755
you must put the function in head DEMO
<button id="but" type="button" onclick="doubleSize(document.getElementById('inpt').value)" >click me!</button>
Upvotes: 0
Reputation: 4523
Here you go: Fiddle : http://jsfiddle.net/cUA9K/1/
<button id="but" type="button" onclick="doubleSize(document.getElementById('inpt').value)" >click me!</button>
Upvotes: 0
Reputation: 1570
Try to pass it like this:
onclick="doubleSize(document.getElementById('inpt').value)"
Upvotes: 4