html - Calling a javascript function -
i need call javascript function run progress bar, here code:
<form name="calculation" method="post"> <progress id="progressbar" value="0" max="100" style="width:300px;"> </progress> <span id="status"></span> <h1 id="finalmessage"></h1> <input type="button" id="btn2" value="press me!" onclick="function progressbarsim(al)"/> </form> <script> function progressbarsim(al) { var bar = document.calculation.getelementbyid('progressbar'); var status = document.calculation.getelementbyid('status'); status.innerhtml = al + "%"; bar.value = al; al++; var sim = settimeout("progressbarsim(" + al + ")", 1); if (al == 100) { status.innerhtml = "100%"; bar.value = 100; cleartimeout(sim); var finalmessage = document.getelementbyid('finalmessage'); } } var amountloaded = 0; progressbarsim(amountloaded); </script>
the javascript function works on own need run when button pressed , nothing happnes when press button "press me".! idea what's wrong? thanks
you need call function in "onclick", instead of writing "function progresbarsim()". also, "document.calculation.getelementbyid" produces js error, should write "document.getelementbyid". try this:
<form name="calculation" method="post"> <progress id="progressbar" value="0" max="100" style="width:300px;"> </progress> <span id="status"></span> <h1 id="finalmessage"></h1> <input type="button" id="btn2" value="press me!" onclick="progressbarsim(0)"/> </form> <script> function progressbarsim(al) { var bar = document.getelementbyid('progressbar'); var status = document.getelementbyid('status'); status.innerhtml = al + "%"; bar.value = al; al++; var sim = settimeout("progressbarsim(" + al + ")", 1); if (al == 100) { status.innerhtml = "100%"; bar.value = 100; cleartimeout(sim); var finalmessage = document.getelementbyid('finalmessage'); } } var amountloaded = 0; progressbarsim(amountloaded); </script>
Comments
Post a Comment