...

View Full Version : innerHTML won't work



ghornet
04-02-2003, 06:06 PM
not sure if this is possible, but I am trying to replace the innerHTML of the following code, but innerHTML is not returning anything... the alert box is blank. Is it because it is just the TR tags?



function onclick()
{
alert(document.all['staticHeaders'].innerHTML);
}

<div id="staticHeaders" name="staticHeaders" style="position:absolute">
<tr>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Store">Store</a></td>
<td nowrap width="50"><a class="tablink" href="wpServSurvey.asp?Sort=Days">Service Date</a></td>
<td width="140"><a class="tablink" href="wpServSurvey.asp?Sort=Contact">Contact</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=HomePhone">Home Phone</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date1">Call 1</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date2">Call 2</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date3">Call 3</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=LetterDate">Mail</a></td>

</tr>
</div>
Thanks

D--

beetle
04-02-2003, 06:13 PM
Shouldn't that be document.all('staticHeaders').innerHTML

ghornet
04-02-2003, 06:16 PM
Yes it is.. I tried using getelement and forgot to change it back... it still won't work even with ()

beetle
04-02-2003, 06:23 PM
What's calling the function onclick? Besides the fact that it's a bad idea to name a function the same as an event, I don't see what calls it. Has the DIV staticHeaders fully loaded when it's called?

document.getElementById is a method and uses the parens too

document.getElementById('staticHeaders');

ghornet
04-02-2003, 06:47 PM
This may be a silly idea I don't know, if anyone has any better ways I would love to listen

I have a table that is in iframe, I am trying to keep the header row in one place while the rest of the frame is able to scroll

the header is going to change based on user information so I was going to grab the inner html of the header store it in some javascript so that every time that the user scrolls the iframe the top header of the table is displayed at the top of the iframe. does that make sense? for now I would be happy just to get the alert to work.

here is the code

function place_header()
{
alert(document.all('staticHeaders').innerHTML);
}

//-->
</SCRIPT>
</head>
<body style="scrollbar-base-color: buttonface;" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" onscroll="place_header()">
<input type="hidden" name="Current" id="Current" value="1">
<input type="hidden" name="maxRecord" id="maxRecord" value="<%= iTo %>">
<input type="hidden" name="Records" id="Records" value="<%= iRecs %>">


<table cellSpacing="0" cellPadding="2" width="100%" bgcolor="#1e5c99" border="0" bordercolor="#C0C0C0" bordercolorlight="#C0C0C0" style="border-collapse: collapse">
<div id="staticHeaders" name="staticHeaders" style="position:absolute">
<tr>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Store">Store</a></td>
<td nowrap width="50"><a class="tablink" href="wpServSurvey.asp?Sort=Days">Service Date</a></td>
<td width="140"><a class="tablink" href="wpServSurvey.asp?Sort=Contact">Contact</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=HomePhone">Home Phone</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date1">Call 1</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date2">Call 2</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=Date3">Call 3</a></td>
<td nowrap><a class="tablink" href="wpServSurvey.asp?Sort=LetterDate">Mail</a></td>

</tr>
</div>

joh6nn
04-02-2003, 06:48 PM
beetle, it's my understanding that when it was introduced in IE4, document.all was an array, so that brackets would have been appropriate. later, it became a sort of getter function/object, so they switched to parentheses. as of now, i'm pretty sure that either is acceptable, but i don't really use it all that often, so i could be wrong.

liorean
04-02-2003, 06:50 PM
It shouldn't be legal to do function onclick since onclick DOES exist (it's declared but not defined). Function statements and variables share namespace, so if some variable name is declared, the function won't work.

Try doing the old window.onclick=function(){} way instead.


(Hmm, guess I was wrong:

Warning: redeclaration of var t
Source File: javascript: var t;function t(){return true};[t,t()];
Line: 1, Column: 31
Source Code:
var t;function t(){return true};[t,t()];
only gives warning, not error, and the function overwrites the variable. Well, I don't think host objects behave the same, anyway.)

liorean
04-02-2003, 06:54 PM
In fact, document.all is neither JSArray nor VBArray - it's a dynamic collection made to look as a native array to JS and VB. The reason it works with () wasn't intended - it's just that JScript has support for VBArray and thus can use both interfaces to it.

joh6nn
04-02-2003, 06:55 PM
i'd suggest putting the iframe in 2 row table. in the top row, you put the header information, and the bottom row has the iframe in it, and the iframe has the rest of the table in it.

there may be a better way to do this, that doesn't use an iframe at all, but that's getting a little more complicated that needs be at the moment.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum