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:

  1. assign onclick function button. called whenever button clicked.
  2. an id added both button tag , div tag access them using getelementbyid method in javascript.
  3. this.value pass value of button clicked function.
  4. inside javascript, value of button , set innerhtml of required div. note: since += used, take current contents of div , 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; } 

demo


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -