0

There is textbox, and 2 buttons in a web page. when the user clicks one of the button, the character 'A', should get printed on the textbox. and when the user clicks on the other button, 'B', should get printed on the textbox in the format 'AB'.

I was looking to do this in HTML, but i don't think i can use only HTML to achieve this. is this correct? Some says Javascript could do this, if so could someone help me with a sample code to begin with or a website that explains this. I did google this, but was unable to find a solution.

Thank you in advance

2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by localp
0

this may be help.

<html>
<body>
<input type="text" name="f1" id="f1">
<input type="button" value="First Button" onClick="javascript:document.getElementById('f1').value='A';">
<input type="button" value="Second Button" onClick="javascript:document.getElementById('f1').value='AB';">
</body>
</html>

SNIP

Edited by happygeek: fake sig snipped

0

this may be help.

<html>
<body>
<input type="text" name="f1" id="f1">
<input type="button" value="First Button" onClick="javascript:document.getElementById('f1').value='A';">
<input type="button" value="Second Button" onClick="javascript:document.getElementById('f1').value='AB';">
</body>
</html>

http://codewall.blogspot.com

thanks for the quick reply, but how do you append 'B' to 'A'. I mean If there are 2 buttons Button A and Button B. When we click button A , the character 'A' should be displayed on the textbox, and when we press button B, the character 'A' (which came from button A), followed by character 'B' (which came from button B) should appear like 'AB'.

in other words B should append to A, and the output should be 'AB'. how do i solve this.

1

try this..

<html>
<body>
<input type="text" name="f1" id="f1">
<input type="button" value="First Button" onClick="javascript:document.getElementById('f1').value+='A';">
<input type="button" value="Second Button" onClick="javascript:document.getElementById('f1').value+='B';">
</body>
</html>

SNIP

Edited by happygeek: fake sig snipped

0

try this..

<html>
<body>
<input type="text" name="f1" id="f1">
<input type="button" value="First Button" onClick="javascript:document.getElementById('f1').value+='A';">
<input type="button" value="Second Button" onClick="javascript:document.getElementById('f1').value+='B';">
</body>
</html>

http://codewall.blogspot.com

Oh yeah.. it worked. '+' sign means append i guess. Thank you very much

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.