...

View Full Version : ARG! Why doesn't document.getElementById find my control!



nmesick
07-20-2011, 07:27 PM
I'm a green with Ajax, can someone help?

http://dev.messicks.com/commoncatalog.aspx?brandcode=NH&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?

sunfighter
07-20-2011, 11:25 PM
You are using the document.getElementById wrong!!


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.

Philip M
07-21-2011, 09:24 AM
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'.

nmesick
07-21-2011, 02:11 PM
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.

Old Pedant
07-22-2011, 12:44 AM
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

<input name="sdwidth" type="hidden" id="sdwidth" />

and so doing

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.

sunfighter
07-22-2011, 01:00 AM
If your looking to find the length and width of the browser window using js, look here:
http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum