Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    JS wont pass variable

    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:

    Code:
    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 ?

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Event handlers must be passed a reference to a function:window.onload = function(){ fill_div(area+':'+x+':'+y); }

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I see now thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •