javascript - Button value set in editable div when click on -
i using button tag <button value="1">1</button>
basically want when button pressed, value of button set editable div.
<div contenteditable='true'; >value button</div>
is possible client side script?
try below code: (edit modified user has subsequently indicated use create calculator)
we doing following:
- assign onclick function button. called whenever button clicked.
- an id added both
button
tag ,div
tag access them usinggetelementbyid
method in javascript. this.value
passvalue
ofbutton
clicked function.- inside javascript, value of button , set
innerhtml
of requireddiv
. note: since+=
used, take current contents ofdiv
, append button's value (like, if 1 pressed followed 2,div
have 12 content).
html
<button value="1" id='btn1' onclick='setbtnvalue(this.value);'>1</button> <button value="2" id='btn2' onclick='setbtnvalue(this.value);'>2</button> <div contenteditable='true' id='div1'></div>
javascript
function setbtnvalue(btnval){ document.getelementbyid('div1').innerhtml += btnval; }
Comments
Post a Comment