fikiwan Posted December 14, 2012 Share Posted December 14, 2012 (edited) Hey all .. I do a tes for make a global varibel in Javascriptfirst time I try like it var satu = 10;var dua = 5;function hitung(){document.write(satu+dua);} no problem so far,.. and I try for second like this: I want display a tag hidden with action onClick , var mun = document.getElementById("mun");function muncul(){ mun.style.display ="block";}<a href="#" onClick="muncul();">Tes For Muncul</a><div id="mun" style="display:none;">Saya Akan Muncul Disini Baby</div> its not work so I try for the third like this: function muncul(){var mun = document.getElementById("mun");mun.style.display ="block";}<a href="#" onClick="muncul();">Tes For Muncul</a><div id="mun" style="display:none;">Saya Akan Muncul Disini Baby</div> and it's run very well ; So , I had a question whether a tag can't be for a global Variabel , cause I have need variable same for any function, Thanks Edited December 14, 2012 by fikiwan Link to comment Share on other sites More sharing options...
Don E Posted December 14, 2012 Share Posted December 14, 2012 When the window loads, you have to set your global variables to what you want them to be set to, so that they can be accessible to functions etc. So for example: <script type="text/javascript">var mun; window.onload = function() { mun = document.getElementById("mun"); } function muncul() { mun.style.display = "block"; }</script> 1 Link to comment Share on other sites More sharing options...
fikiwan Posted December 18, 2012 Author Share Posted December 18, 2012 thank for the help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now