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

Recommended Answers

All 4 Replies

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

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.