0

I have a text box where i need to load the data when form is loaded. In "G6data" variable i am getting the value 100 but it is not getting populated in G6 text box. How can i populate the data which i got into input box using getElementByID. Please help

   <!DOCTYPE html>
        <html>
        <body onload="myFunction()">        
        <input type="text" id="f6" value="5000" />
        <input type="text" id="G6" value="" />
        <button >Try it</button>        
        <script>
        function myFunction()
        {
        var F6=document.getElementById("F6").value;
           var as6=calculateAS6(F6);    
           var as4=CalculateAS4(as6);
           var G6data=AveragePercentage(as6,as4);
document.getElementById("G6").innerHTML=G6data;       
        }
        </script>       
        </body>
        </html>

3 Answers 3

3

You have mistake in Input element and for give value to any text box we use .value insted of .innerHTML.

Use this code

     <html>
        <body onload="myFunction()">        
         <input type="text" id="f6" value="5000" />
         <input type="text" id="G6" value="" />
         <button >Try it</button>        
        <script>
        function myFunction()
        {
        var F6=document.getElementById("f6").value;
           var as6=calculateAS6(F6);    
           var as4=CalculateAS4(as6);
           var G6data=AveragePercentage(as6,as4);
        document.getElementById("G6").value=G6data;       
        }
        </script>       
        </body>

      </html>
Sign up to request clarification or add additional context in comments.

Comments

0

It should be value

document.getElementById("G6").value=G6data;  

Comments

0

There is a simple problem here

<input type="text" id="f6" value="5000" />

Your id here is 'f6' while you are trying to fetch element with an id of 'F6' here

var F6=document.getElementById("F6").value;

and use value instead of innerHTML here

document.getElementById("G6").innerHTML=G6data;

Comments