RASHEED RAMSHI RASHEED RAMSHI - 7 months ago 25
HTML Question

how to display inner HTML output in text box

I am a beginner html and js programmer and I am trying to display inner HTML output into another TextBox.The code I am using does not give the output in the text box.Can anyone tell me what is wrong with this code?
this is my code

<script>
function my()
{

var a=document.getElementById("text").value;
document.getElementById("demo").innerHTML=a;
}
</script>

<input type="text" id="text" onKeyUp="my()"><br><br>
<span id="demo">
<input type="text" id="demo">
</span>


Any Help is Appreciated...Thanks

Answer

You have the same id attribute for both span and your input i.e "demo". Change the span id and try it

The below works:

<script>
    function my()
    {

      var a=document.getElementById("text").value;
      document.getElementById("demo").value=a;
    }
</script>

<input type="text" id="text" onKeyUp="my()"><br><br>
<span id="demo_span">
    <input type="text" id="demo">
</span>
Comments