Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to add text data inside a textbox alongside data inside text box by clicking buttons, the problem am facing is when i click button with data inside the data gets cleared , i want to keep the data and insert button data along side it , any help?

What I have tried:

function Bold()
{
document.getElementById("result").value= '< b >< /b >';
}

function Italic()
{
document.getElementById("result").value= '< i >< /i >';
}

<input type="button" value="Bold" name="no" onclick="Bold()">
                    <input type="button" value="Italic" name="no" onclick="Italic()">

<textarea id="result"></textarea>
Posted
Updated 13-Feb-21 5:14am
v3
Comments
[no name] 13-Feb-21 10:01am    
You assign an empty string e.g. here:
document.getElementById("result").value= '';

Why you wonder that text is empty after that?
Member 11755075 13-Feb-21 10:12am    
no no i added html tags inside but the site didnt display it sorry , so if i click bold , it adds bold tags but if i click italic it should add italic beside bold tag, but its clearing bold tag and adding italic tags
[no name] 13-Feb-21 10:26am    
I don't get it. But anyway think about
document.getElementById("result").value+=
instead of
document.getElementById("result").value=
Member 11755075 13-Feb-21 11:08am    
thanks a lot this works and solved my problem :)
[no name] 13-Feb-21 11:12am    
You are welcome.

1 solution

This one
document.getElementById("result").value= ...

will replace the whole content. So what I understand you like to add and therefore you should take into account something like
document.getElementById("result").value+= ...
 
Share this answer
 
Comments
[no name] 13-Feb-21 11:16am    
And because I'm completely web noob I posted all that first as comment, sorry ;)
Member 11755075 13-Feb-21 11:30am    
haha np :) thanks again :)
[no name] 13-Feb-21 11:38am    
Thank you for accepting an answer from a noob ;)

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