I cannot display a javascript variable to a <p>? -
i don't know wrong code had reference of codes , done cannot display variable pharagraph?
this code on script:
<script type="text/javascript"> var myid = document.getelementbyid('myid').value; // var scope = 'global'; function testscope() { var scope = 'local'; function innerfunc() { return scope; } return innerfunc(); } var answer = testscope(); myid.innerhtml = answer; </script> on html
<p id="myid"><!-- no variable displayed --></p> what doing wrong?
use document.getelementbyid('myid') instead of document.getelementbyid('myid').value. because <p> element hasn't value property
function checkfunctionscope() { var myid = document.getelementbyid('myid'); var scope = 'global'; function testscope() { var scope = 'local'; function innerfunc() { return scope; } return innerfunc(); } var answer = testscope(); myid.innerhtml = answer; } window.onload = checkfunctionscope; <p id="myid"> <!-- no variable displayed --> </p>
Comments
Post a Comment