Reputation: 1
I try when I click on 1 button to have the value 1 in the first(blank) button but my code doesn't work and the value of first button become 1 before I click
HTML code
<html>
<head>
<title>
Exemplu
</title>
</script>
</head>
<body>
<form>
<input type="button" value="" id= "say_result"/>
</form>
<form>
<input type="button" value="1" id= "say_one"/>
</form>
<form>
<input type="button" value="2" id= "say_two"/>
</form>
<form>
<input type="button" value="+" id= "say_plus"/>
</form>
<form>
<input type="button" value="-" id= "say_minus"/>
</form>
<form>
<input type="button" value="=" id= "say_equal"/>
</form>
<script type="text/javascript" src=exemplu3.js></script>
</body>
</html>
Javascript code
function cifr(vallue){
var local_Value = vallue;
return document.getElementById("say_result").value = local_Value;
}
var oneButton = document.getElementById("say_one")
oneButton.onclick = cifr(1);
function two(){
document.getElementById("say_result").value = "2";
return 2;
}
var oneButton = document.getElementById("say_two")
oneButton.onclick = two;
Upvotes: 0
Views: 1623
Reputation: 499352
In the following line:
oneButton.onclick = cifr(1);
You are calling the cifr
function with the argument 1
and assigning the result to the oneButton
click event.
This should probably be:
oneButton.onclick = function(){cifr(1);};
Upvotes: 1