/    Sign up×
Community /Pin to ProfileBookmark

Adding/Changing Text in a DIV tag

Hello,

I’m trying to use the following function to change the text that lies between a DIV tag, however its not working any ideas…

function changeDateValue()
{
advisory = document.getElementById(‘div_w0d2’);
advisory.removeChild(advisory.childNodes[0]);
advisory.appendChild(document.createTextNode(‘1’));
}

and the HTML…

<table border=”1″>
<tr>
<td width=”25″ id=”td_w0d0″><div id=”div_w0d0″></div></td>
<td width=”25″ id=”td_w0d1″><div id=”div_w0d1″></div></td>
<td width=”25″ id=”td_w0d2″><div id=”div_w0d2″></div></td>
<td width=”25″ id=”td_w0d3″><div id=”div_w0d3″></div></td>
<td width=”25″ id=”td_w0d4″><div id=”div_w0d4″></div></td>
<td width=”25″ id=”td_w0d5″><div id=”div_w0d5″></div></td>
<td width=”25″ id=”td_w0d6″><div id=”div_w0d6″></div></td>
</tr>
</table>

When the function executes, the IDEA is to place a ‘1’ in the div tag and thus in corresponding table cell, however I keep getting the cryptic message:

Error: uncaught exception: [Exception… “Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLDivElement.removeChild]” nsresult: “0x80004003 (NS_ERROR_INVALID_POINTER)” location: “JS frame :: file:///I:/developement/datepicker.html :: changeDateValue :: line 36” data: no]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@pyroMar 08.2003 — You can do it like this:

document.getElementById('div_w0d2').innerHTML = "1";
Copy linkTweet thisAlerts:
@khalidali63Mar 08.2003 — ?

Hey how about this.

<i>
</i>&lt;script type="text/javascript"&gt;
function changeDateValue(){
var nl = document.getElementsByTagName("td");
for(x=0;x&lt;nl.length;x++){
obj = nl[x];
obj.innerHTML = (x+1);
}
}
window.onload = changeDateValue;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;table border="1"&gt;
&lt;tr&gt;
&lt;td width="25" id="td_w0d0"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d1"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d2"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d3"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d4"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d5"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="25" id="td_w0d6"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;


Cheers

Khalid
Copy linkTweet thisAlerts:
@davidcholleyauthorMar 08.2003 — If I'm correct .innerHTML isn't a standard and thus will only work for MSIE.
Copy linkTweet thisAlerts:
@pyroMar 08.2003 — .innerHTML will also work in NN/Mozilla, etc.

.innerTEXT is IE only.
Copy linkTweet thisAlerts:
@khalidali63Mar 08.2003 — The solution I posted is both IE and NS6+ compatible it is DOM based so the

"Code of the future" as some may call it..

?

Khalid
Copy linkTweet thisAlerts:
@pyroMar 08.2003 — The code I posted will work in IE6, Opera 7, NN7, and Mozilla 1.2, and probably more... ?
×

Success!

Help @davidcholley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...