How can I change global variables in javascript? -


my html page displays button calls function when clicked. checked make sure button works displaying message when clicked , worked. created function change global varible when click button on html page show value of varibles varibles have not changed value set them using function. find problem in code below?

    var = 5;     var b = 16;     var c = 27;      function reset(){     = 0;     b = 0;     c = 0;     } 

my html code call function:

   <!doctype html>     <html>    <center>    <script type="text/javascript" src="game.js" > </script>    <form>    <input type="button" value="reset variables" style="width:250px;height:50px" onclick="reset()" >    </form>    </html> 

javascript code show variables:

    function display(){      document.write("a equal " + + "<br/>");     document.write("b equal " + b + "<br/>");     document.write("c equal " + c );  } 

html display variables

   <!doctype html>     <html>    <center>    <script type="text/javascript" src="game.js" > </script>    <form>    <input type="button" value="show variables" style="width:250px;height:50px" onclick="display()" >    </form>    </html> 

change function name reset_vars or else. reset() in-built dom function used resetting forms.

http://www.w3schools.com/jsref/met_form_reset.asp

there won't conflict when global variable used inside function unless local variable defined. in such case, use window.variable_name access global variable.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -