Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3423368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:20:48+00:00 2026-05-18T06:20:48+00:00

Hello Friends I am facing some problem or can say not figure out any

  • 0

Hello Friends
I am facing some problem or can say not figure out any help regard this so please help me
There is button having name Add Text when I click that button it display a text box when i enter some text in this text box it display the entered text below.when I click again Add Text button then previous one textbox seems empty i don’t want this.

1.) My requirement is when I click Add Text button second time it doesn’t empty the previous textbox.

2.) when i click the B button then it convert the text to bold.Right now its working for one text i want when i select particular text and click B button it convert the particular selected text to bold.
These are my two problem.Please reply if anybody having the solution of my problem.
Thanks

<script type="text/javascript">
   var i=0;
   function add_input()
        {
          if(i!=6){
              var d=document.getElementById('div');

           d.innerHTML+="<input type='text'  name='addtext"+i+"' id='addtext"+i+"'onkeyup='copy("+i+")'><br></br>";
                 i++;
                 }

        }
  function copy(j){

           var mm = 'addtext'+j;
           var divid = 'newcontent'+j;
           var s1=document.getElementById(mm).value;

           /*var s2=document.getElementById('newcontent'+j);*/
           var s2=document.getElementById('newcontent'+j);

           s2.innerHTML=s1;


            }
          </script>


      <script type="text/javascript">
          function f2() {

               if(document.getElementById('newcontent0').style.fontWeight =='bold')
                    {
                         document.getElementById('newcontent0').style.fontWeight = 'normal';
                    }
                   else if(document.getElementById('newcontent0').style.fontWeight =='normal')
                     {
                        document.getElementById('newcontent0').style.fontWeight = 'bold';
                      }
                  else if(document.getElementById('newcontent0').style.fontWeight =='')
                     {
                        document.getElementById('newcontent0').style.fontWeight = 'bold';
                      }
              }
             </script>

     <input  type="button" value="Add Text" onclick="add_input()"  />
     <input type="button"  value="B"  onclick="f2()"/> 
     <div id="div"></div>
     <div id="newcontent0"  style="padding:0px;margin:0px;"></div>
     <div id="newcontent1"  style="padding:0px;margin:0px;"></div>
     <div id="newcontent2"  style="padding:0px;margin:0px;"></div>
     <div id="newcontent3"  style="padding:0px;margin:0px;"></div>
     <div id="newcontent4"  style="padding:0px;margin:0px;"></div>

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:20:48+00:00Added an answer on May 18, 2026 at 6:20 am

    1.) My requirement is when I click Add Text button second time it doesn’t
    empty the previous textbox.

    This happens because you replace the innerHTML. Any text you have typed into the input field will not be retained, because it’s not part of the new innerHTML.

    To prevent this from happening, you can manipulate the DOM instead. It may be a bit more code and theoretically somewhat slower, but in this case that’s not something you need to worry about.

    2.) when i click the B button then it convert the text to bold.Right now its
    working for one text i want when i
    select particular text and click B
    button it convert the particular
    selected text to bold.

    This one is a little trickier. We need to remember which input field was last selected, so that f2() can set the fontWeight of the correct element. You can do that by using the onblur event of the input elements and having a variable lastFocused remembering which one was last selected.

    All in all, something like this should work (try here: http://jsfiddle.net/2euLZ/) :

    var i = 0;
    var lastFocused = null;
    
    function add_input()
    {
        if(i != 6){
            var d=document.getElementById('div');
            var newId    = i;
    
            var newInput = document.createElement("input");
            newInput.type    = "text";
            newInput.name    = "addtext" + i;
            newInput.id      = "addtext" + i;
            newInput.onkeyup = function() { copy(newId); };
            newInput.onblur  = function() { lastFocused = newId; };
    
            d.appendChild(newInput);
            d.appendChild(document.createElement("br"));
            i++;
        }
    }
    
    function copy(j)
    {
           var s1 = document.getElementById('addtext'+j);
           var s2 = document.getElementById('newcontent'+j);
           s2.innerHTML = s1.value;
    }
    
    function f2() {
        var target = document.getElementById("newcontent" + lastFocused);
    
        var newFontWeight = "bold";
        if(target.style.fontWeight == "bold")
            newFontWeight = "normal";
    
        target.style.fontWeight = newFontWeight;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends I created some custom fields for contacts. How can I insert values
Hello stack overflow I need help with this problem. Ok, I have a flat
Hello Friends I want to know is there any way we can open or
Hello future friends who is gonna help me big time on this project, I
Hello friends I am using this code in my view.. Using this code I
hello Friends please verify my code Is it a right way to pass optional
hello friends i am using this galleria gallery link to display images on my
hello friends i have tryied folowing code as u can see here http://jsfiddle.net/QCdz4/ i
• hello friends, • I have one solution say sol1 ’ which contain one
Hello friends a newbie question... The Issue is like this: I have a static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.