Let's say I have the code below:
function addValue(x){
var button = document.createElement( "input" );
button.setAttribute("type", "submit");
button.setAttribute("src", "images/repeatStageIcon.png");
button.setAttribute("class", "option-image");
button.setAttribute("title", "Repeat Current Stage!");
//HOW TO PASS X AS AN ONCLICK ATTRIBUTE?
button.setAttribute("onclick", "createRepeatStage( x )");
var p = document.getElementById("myDiv");
p.appendChild(button);
}
function createRepeatStage( thisX ){
alert(thisX);
}
addValue(6);
<html>
<body>
<div id="myDiv"></div>
</body>
</html>
QUESTION:
How to pass the x attribute in the onclick event so that when the method createRepeatStage(x); is called, the x value would be passed in that method?