Thanassis
Thanassis

Reputation: 877

How to pass a parameter from an input element

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

Answers (3)

mehdi
mehdi

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

Ani
Ani

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

Shryme
Shryme

Reputation: 1570

Try to pass it like this:

onclick="doubleSize(document.getElementById('inpt').value)"

Upvotes: 4

Related Questions