Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  81] [ 3]  / answers: 1 / hits: 156925  / 12 Years ago, tue, december 18, 2012, 12:00:00

Basically just trying to add text to an input field that already contains a value.. the trigger being a button..



Before we click button, form field would look like.. (user inputted some data)



[This is some text]
(Button)


After clicking button, field would look like.. (we add after clicking to the current value)



[This is some text after clicking]
(Button)


Trying to accomplish using javascript only..


More From » jquery

 Answers
34

Example for you to work from



HTML:



<input type=text value=This is some text id=text style=width: 150px; />
<br />
<input type=button value=Click Me id=button />​


jQuery:



<script type=text/javascript>
$(function () {
$('#button').on('click', function () {
var text = $('#text');
text.val(text.val() + ' after clicking');
});
});
<script>


Javascript



<script type=text/javascript>
document.getElementById(button).addEventListener('click', function () {
var text = document.getElementById('text');
text.value += ' after clicking';
});
</script>


Working jQuery example: http://jsfiddle.net/geMtZ/


[#81347] Monday, December 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anais

Total Points: 672
Total Questions: 118
Total Answers: 121

Location: Oman
Member since Fri, Dec 23, 2022
1 Year ago
anais questions
Fri, Jul 29, 22, 00:00, 2 Years ago
Mon, Jul 19, 21, 00:00, 3 Years ago
Tue, May 11, 21, 00:00, 3 Years ago
Fri, Apr 2, 21, 00:00, 3 Years ago
;