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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ARG! Why doesn't document.getElementById find my control!

    I'm a green with Ajax, can someone help?

    http://dev.messicks.com/commoncatalo...H&modelid=8374

    @ page.load the init() function on this page will find everything just fine. However if I call init() after the load it does not find the referenced controls. My goal is to set the imageurl in the hidden "imageurl" textbox, then call init from the treeview to reload the image. Not rocket science, IF I could get it to find the controls.

    What I don't get is the results from the "get objects" text box I put at the top. If I look though all the elements on the page, shouldn't I see a heck of a lot more than this?
    Last edited by nmesick; 07-20-2011 at 06:36 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    You are using the document.getElementById wrong!!

    Code:
            function Init() {
                var width = parseInt(document.getElementById("width").value);
                var height = parseInt(document.getElementById("height").value);
                var imageUrl = document.getElementById("imageUrl").value;
                var tileSize = parseInt(document.getElementById("tileSize").value);
                var tileOverlap = parseInt(document.getElementById("tileOverlap").value);
                var tileSource = new Seadragon.TileSource(width, height, tileSize, tileOverlap);
                tileSource.getTileUrl = function (level, x, y) {
                    return "/seadragon/SeaDragonHandle.ashx?level=" + level + "&x=" + x + "&y=" + y +
                       "&tileSize=" + tileSize + "&tileOverlap=" + tileOverlap + "&image=" + imageUrl;
                }
    This var width = parseInt(document.getElementById("width").value); does find your width. It is looking for an element that has the ID of width. AND you do not have anything with that ID. AND you should use that word as an ID.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Note that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an HTML element name or ID.
    You should also avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/properties/attributes such as 'name' or 'id' or 'value' or 'test' or 'text' or 'checked' or 'go' or 'replace' or 'button' or 'radio' or 'parseInt'.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Note that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an HTML element name or ID.
    You should also avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/properties/attributes such as 'name' or 'id' or 'value' or 'test' or 'text' or 'checked' or 'go' or 'replace' or 'button' or 'radio' or 'parseInt'.
    so I changed the ID's to something more unique, but I still have the same problem. The Init() function runs a-okay on pageload, but does not afterwards. See the link above.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I'm lost.

    Your Init() function doesn't seem to ever get called. (I set a breakpoint on it with Firebug and never hit the breakpoint.) If it were called, I don't see how it would work, because (for example) you have
    Code:
    <input name="sdwidth" type="hidden" id="sdwidth" />
    and so doing
    Code:
    var width = parseInt(document.getElementById("sdwidth").value);
    is going to give you an invalid value for your width variable. (The value of that field will be the blank string "", and parseInt("") will give you NaN -- Not a Number.)

    But, again, Init() is *NOT* called "on pageload", according to Firebug. So I guess it doesn't matter. In fact, I can't figure out how to force Init() to get called.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    If your looking to find the length and width of the browser window using js, look here:
    http://andylangton.co.uk/articles/ja...ze-javascript/


  •  

    Posting Permissions

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