BigMan157 no u 103354 Posts user info edit post |
i'm looking for JS code that can change the contents of a span or div that will work in firefox, similar to http://www.faqts.com/knowledge_base/view.phtml/aid/7916 but FF compatible
i'm not sure if it is something i'm doing or what, but i can't get it to work 6/12/2006 5:03:19 PM |
A Tanzarian drip drip boom 10995 Posts user info edit post |
<script type="text/JavaScript">
...
function Tick() { document.getElementById("counterOne").innerHTML = TimeSince(2006, 5, 1, 0, 0); document.getElementById("counterTwo").innerHTML = TimeUntil(2006, 10, 30, 24, 0); } </script> </head>
<body onload="window.tmr = setInterval(Tick, 999)" onunload="clearInterval(window.tmr)">
...
<span id="counterOne"><script type="text/JavaScript">document.write(TimeSince(2006, 5, 0, 0, 0))</script></span>
This is from a JavaScript timer that I wrote. What you want is in bold. Make sure that you use document.getElementByID() to reference the object and innerHTML to change the text inside the span.
The problem with the link you posted is that document.all and innerText are specific to Microsoft's JScript, and are not part of JavaScript.
[Edited on June 12, 2006 at 6:58 PM. Reason : .]6/12/2006 6:57:52 PM |
qntmfred retired 40726 Posts user info edit post |
Quote : | "H4X0R All American 56592 Posts user info edit post" |
6/12/2006 7:47:01 PM |
BigMan157 no u 103354 Posts user info edit post |
alright, i'm still having no luck, let me post some code
here's the function that gets called to modify the info in the span
function textCounter(field,cntfield,maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else cntfield.innerHTML = maxlimit - field.value.length; }
and here is the code that calls it and what it modifies (forgive the php)
echo' <td nowrap style="vertical-align:top"><b><span id="counter' . $counter . '" name="counter['.$counter.']">400</span></b> characters remaining</td>'; echo' <td><textarea id="comments' . $counter . '" name="comments[' . $counter . ']" rows="4" cols="60" wrap maxlength="400" onKeyDown="textCounter(document.form.getElementByID(\'comments'.$counter.'\'),document.form.getElementByID(\'counter' . $counter . '\'),400)" onKeyUp="textCounter(document.form.getElementByID(\'comments'.$counter.'\'),document.form.getElementByID(\'counter' . $counter . '\'),400)"'; echo'>';
and an example minus the php
<td nowrap style="vertical-align:top"><b><span id="counter0" name="counter[0]">400</span></b> characters remaining</td> <td><textarea id="comments0" name="comments[0]" rows="4" cols="60" wrap maxlength="400" onKeyDown="textCounter(document.form.getElementByID('comments0'),document.form.getElementByID('counter0'),400)" onKeyUp="textCounter(document.form.getElementByID('comments0'),document.form.getElementByID('counter0'),400)"></textarea></td>
[Edited on June 12, 2006 at 8:24 PM. Reason : that should help clear it up i hope]6/12/2006 8:20:13 PM |
A Tanzarian drip drip boom 10995 Posts user info edit post |
<td><textarea id="comments0" name="comments[0]" rows="4" cols="60" wrap maxlength="400" onKeyDown="textCounter(document.getElementById('comments0'),document.getElementById('counter0'),400)" onKeyUp="textCounter(document.getElementById('comments0'),document.getElementById('counter0'),400)"></textarea></td>
This works.
The function is document.getElementById() not document.getElementByID(). I got it wrong in my post earlier...sorry You shouldn't need the "form" part either.6/12/2006 8:58:23 PM |
BigMan157 no u 103354 Posts user info edit post |
WOOO it works
thx dude 6/12/2006 10:16:17 PM |
|