I recently experienced an odd issue: A JavaScript function refers to an input field by ID (the ID is used as a function parameter). When no document type is specified at the top of the HTML page, this works fine, but adding a document type declaraction (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">)
breaks the script. It claims that the object specfified by the ID cannot be found.
Is there any interaction between the document type and this seemingly basic DOM reference?
On Wed, Jan 13, 2010 at 04:24:48AM -0800, janedenone wrote: > Hi,
> I recently experienced an odd issue: A JavaScript function refers to > an input field by ID (the ID is used as a function parameter). When no > document type is specified at the top of the HTML page, this works > fine, but adding a document type declaraction (<!DOCTYPE HTML PUBLIC > "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd">)
> breaks the script. It claims that the object specfified by the ID > cannot be found.
> Is there any interaction between the document type and this seemingly > basic DOM reference?
I think it would be helpful to see the JavaScript function and the HTML for the input field.
<janeden...@googlemail.com> wrote: >Is there any interaction between the document type and this seemingly >basic DOM reference?
I have seen a few cases where invalid syntax can cause that. Do a document syntax check and look for errors. An improperly closed tag could cause that.
Charlie
-- Ꮚ Charlie Garrison ♊ <garri...@zeta.org.au> 〠 PO Box 141, Windsor, NSW 2756, Australia
> I recently experienced an odd issue: A JavaScript function refers to > an input field by ID (the ID is used as a function parameter). When no > document type is specified at the top of the HTML page, this works > fine, but adding a document type declaraction (<!DOCTYPE HTML PUBLIC > "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd">)
> breaks the script. It claims that the object specfified by the ID > cannot be found.
> Is there any interaction between the document type and this seemingly > basic DOM reference?
If you're going to declare a doctype, it'd be best to validate that your page conforms to the type.
and this is the JavaScript code (also abbreviated):
function selectTime(ctl,ctl2) { var id2=ctl2; ctl2 = document.getElementById(id2); textCtl = ctl2;
if ((currentCtl != ctl) && (currentCtl !== null)) { // not the same currentCtl.src = imagePath + "timepicker.gif"; // prev button in released state } currentCtl = ctl; currentCtl.src = imagePath + "timepicker2.gif"; // curr button pressed state
ctl2.value === "" ? '12:00' : ctl2.value; var res=validateDatePicker2(ctl2); if (res){ refreshTimePicker(ctl2.value); } else{ refreshTimePicker(0); }
> On Wed, Jan 13, 2010 at 04:24:48AM -0800, janedenone wrote: > > Hi,
> > I recently experienced an odd issue: A JavaScript function refers to > > an input field by ID (the ID is used as a function parameter). When no > > document type is specified at the top of the HTML page, this works > > fine, but adding a document type declaraction (<!DOCTYPE HTML PUBLIC > > "-//W3C//DTD HTML 4.01 Transitional//EN" > > "http://www.w3.org/TR/html4/loose.dtd">)
> > breaks the script. It claims that the object specfified by the ID > > cannot be found.
> > Is there any interaction between the document type and this seemingly > > basic DOM reference?
> I think it would be helpful to see the JavaScript function and the HTML for > the input field.
I managed to solve the initial issue after changing the element reference syntax, but there's one more problem. The overlay created by the JS function is placed at the upper left of the window, instead of the icon which is clicked to display the overlay. This is the function to calculate the overlay position (used for crossobj element quoted above):
// get absolute position of a control. use with overlays, dropdowns, etc. function getAbsPos(ctl) { var leftpos = 0; var toppos = 0; var aTag = ctl; do { aTag = aTag.offsetParent; leftpos += aTag.offsetLeft; toppos += aTag.offsetTop; } while(aTag.tagName != "BODY");
var o = new Object(); o.left = leftpos; o.top = toppos; return o; }
What could I change about this function to ensure the overlay is placed correctly?
Thanks, Jan
On Jan 18, 3:34 pm, Ronald J Kimball <r...@tamias.net> wrote: