Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is a single textbox and i have a button. Button value is 1. I want to display the value of button in textbox using JavasScript.
Posted
Comments
DamithSL 13-Jul-15 4:07am    
what have you tried so far?

1 solution

You may do like this-
JavaScript
document.getElementById("YouTextboxId").value=document.getElementById("YouButtonId").value;


Hope, it helps :)
 
Share this answer
 
Comments
Suvendu Shekhar Giri 13-Jul-15 5:19am    
Glad to know that it helped :)

Please mark it as Answer by doing "Accept Solution" if it helped you so that others can take reference of it if they face similar problem.
Thanks !
Member 11808002 13-Jul-15 5:39am    
complete code snippet for getting desired result:
window.onload = function() {
document.getElementById('btnone').addEventListener('click', function(){
document.getElementById('textBox').value = document.getElementById('textBox').value + document.getElementById('btnone').value;
});
}

HTML:
<input type="button" name="btnone" id="btnone" value="1" />
<input type="button" name="btntwo" id="btntwo" value="2" />
<input type="button" name="btnthree" id="btnthree" value="3" />

<input type="text" name="textBox" id="textBox" value=""/>

What if there are more than one buttons? User have the option to press any of button? these

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900