skip to Main Content

What I want is to transfer data value from ID one to ID two Data should be in the form of a submit button

javascript

<blockquote contenteditable="true" id = "1"><p></p> </blockquote>
<blockquote contenteditable="true" id = "2"><p></p> </blockquote>
<button type="Submit" >Submit</button>

2

Answers


  1. you can use the innerHTML property for quick solution

    let btn = document.getElementById('sbmt');
    let one = document.getElementById('1')
    let two = document.getElementById('2')
    
    
    btn.addEventListener('click', () =>
     {                  
      two.innerHTML= one.innerHTML;
    });
      
      <blockquote contenteditable="true" id = "1"><p> first box</p> </blockquote>
    <blockquote contenteditable="true" id = "2"><p>second box</p> </blockquote>
    <button type="Submit" id=sbmt>Submit</button>
    Login or Signup to reply.
  2. Here’s an example to transfer the content from the first blockquote with the id "1" to the second blockquote with the id "2" when the submit button is clicked.

        <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Blockquote Copy Example</title>
    </head>
    <body>
    
    <blockquote contenteditable="true" id="1"><p></p></blockquote>
    <blockquote contenteditable="true" id="2"><p></p></blockquote>
    <button type="button" onclick="transferData()">Submit</button>
    
    <script>
        function transferData() {
            // Get the content of the first blockquote
            var content1 = document.getElementById('1').innerText;
    
            // Set the content of the second blockquote
            document.getElementById('2').innerText = content1;
        }
    </script>
    
    </body>
    </html>
    

    transferData() method is triggered when submit button is clicked and this method retrieves the content from 1st id and transfers it to 2nd id.

    Also replace the button type with "button" to prevent it from submitting a form, as we’re handling the functionality with JavaScript.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search