EchoFool Posted December 19, 2010 Share Posted December 19, 2010 Hey I have a JS value but it won't put the value in the brackets when i try to get the element by ID instead it is looking for the id named the same as the variable name. Here is what i got to explain better: function fill_div(v) { document.getElementById(v).innerHTML="<img src='untitle.png' style='width:100%;height:100%;'/>"; } var x = 0; var y = 3; var area = 1; window.onload = fill_div(area+':'+x+':'+y); It ends up looking for id v instead of id 1:0:3. Any idea how i correct this ? Link to comment https://forums.phpfreaks.com/topic/222162-function-wont-pass-value/ Share on other sites More sharing options...
requinix Posted December 20, 2010 Share Posted December 20, 2010 window.onload = fill_div(area+':'+x+':'+y); What that says is to execute fill_div (given whatever arguments) and set the result to be window.onload. It does not say that window.onload should execute fill_div (given whatever arguments). When this script is executing, likely the 1:0:3 (which is a horrible ID for an element) element doesn't exist yet. window.onload = function() { fill_div("1:0:3"); }; Tip: learn to add listeners, not to override event handlers. Link to comment https://forums.phpfreaks.com/topic/222162-function-wont-pass-value/#findComment-1149389 Share on other sites More sharing options...
EchoFool Posted December 20, 2010 Author Share Posted December 20, 2010 Listeners? never heard of that ? Link to comment https://forums.phpfreaks.com/topic/222162-function-wont-pass-value/#findComment-1149401 Share on other sites More sharing options...
haku Posted December 20, 2010 Share Posted December 20, 2010 Google is your friend! Event listeners are a very essential part of Javascript. They 'listen' for an event to happen, and then do something when it does. Link to comment https://forums.phpfreaks.com/topic/222162-function-wont-pass-value/#findComment-1149403 Share on other sites More sharing options...
EchoFool Posted December 20, 2010 Author Share Posted December 20, 2010 Okies thanks ! Link to comment https://forums.phpfreaks.com/topic/222162-function-wont-pass-value/#findComment-1149414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.