Click to See Complete Forum and Search --> : innerHTML


tiger66
06-30-2003, 03:11 PM
Hello
I am trying to test my innerHTML like the code below

<script type="text/javascript">
function request(req)
{
if(req="change")
{
test.innerHTML = "hello";
}
}
</script>
</head>

<body>

<input type="radio" name="a" value="new" checked onClick="request(new)">NEW ACCOUNT
<input type="radio" name="a" value="change" onClick="request(change)">CHANGE ACCOUNT
<div id="test">
</div>
</body>

</html>

for some reason it gives me the javascript error and my innerHTML doesn't work

Why??

Please help thanks

Khalid Ali
06-30-2003, 03:23 PM
The way you are trying to reference the div element is old( and wrong in w3c ways) method of accessing elements in IE
to access an element by id you will need to use this

document.getElementById("test").innerHTML = "Hello"

tiger66
06-30-2003, 03:32 PM
I tried both ways already, none of them work
Are there any errors in other parts of my code?

Jona
06-30-2003, 03:33 PM
Originally posted by tiger66
for some reason it gives me the javascript error and my innerHTML doesn't work

You have one equals sign in your if statement, that statement should look like this:


if(req=="change"){


[J]ona

Charles
06-30-2003, 03:49 PM
A couple of things The "old" way is still valid and a part of the W3C DOM. The kind folks included two ways to manipulate HTML. See http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html.html
The INPUT elements have no children, so using "innerHTML" ought not to work.
"innerHTML" isn't a part of the W3C DOM. It's an MSIE thing that has been adopted by some other browsers. You should use something like <label><input type="radio" name="a" value="new" checked onclick="this.parentNode.replaceChild(document.createTextNode('hello'), this.parentNode.lastChild)">NEW ACCOUNT</label>

Khalid Ali
06-30-2003, 03:53 PM
good work jona..:-)

You are such an inconsistent person Charles,
Here I posted a sugestion that is crossbrowser and you had to come back with something that ligitimises the use of a standard thats is not used by all of the browsers..good job man...you keep impressing me day in and day out..

Jona
06-30-2003, 04:11 PM
Originally posted by Khalid Ali
good work jona..:-)

It's the small things in life... ;)

[J]ona

Charles
06-30-2003, 04:19 PM
Originally posted by Khalid Ali
You are such an inconsistent person Charles,
Here I posted a sugestion that is crossbrowser and you had to come back with something that ligitimises the use of a standard thats is not used by all of the browsers..good job man...you keep impressing me day in and day out.. I think that you have mis-read my post wherein I make the following points, 1) That the most widely supported DOM interface (the "old" way) is perfectly valid and described in Chapter 2 of the W3C DOM Level 1 Specification. 2) That "innerHTML" is browser specific and not a part of the W3C DOM . And 3) The there is a perfectly valid and well supported alternative to using "innerHTML".

If you haven't mis-read my post then please tell me of this new meaning for the word "inconsistent".

SlankenOgen
06-30-2003, 05:46 PM
I did a search and came up with this-

http://www.mozilla.org/docs/web-developer/upgrade_2.html

Charles
06-30-2003, 06:01 PM
That's nice, but you can find the real thing at http://www.w3.org/DOM/DOMTR.

Khalid Ali
06-30-2003, 06:06 PM
Originally posted by Charles
points, 1) That the most widely supported DOM interface (the "old" way) is perfectly valid and described in Chapter 2

You have to be like that I guess,
What I posted is perfectly accepted prevailing standard for referencing an html element with an id,what you are advocating is not accepted widely,
My point is if you are so much of an advocate for standards then how come you would try to negate a current prevailing standard with a suggestion from an old standard(only to undermine my suggestion may be???).
I never said anything about innerHTML.
Oh by the way you should go through this article that slankanogan posted above...
Particularly the section below and one after it.
http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_unsupp

And please from my previous experience, we should drop it here,because I have seen you going on and on and on..like energiser bunny on these forums ..:D
Take care

Charles
06-30-2003, 06:29 PM
Please, allow me to point out your incorrect statement, "The way you are trying to reference the div element is old( and wrong in w3c ways) method of accessing elements in IE" - unless I misunderstand you rmeaning, and your slanderous assertion that "innerHTML" is valid W3C DOM. One need only read the specifications to see that you are incorrect and to note that the alternative methods that I suggested were published back in 1998.

I completely agree with your suggestion that this should not be about our ego's. We need to establish what is and what is not. If I am incorrect, I would be in your debt if you would cite a refutation from the specifications. ("innerHTML is so much easier to use that I really hope that I am wrong.)

Khalid Ali
06-30-2003, 11:17 PM
Originally posted by Charles
One need only read the specifications to see that you are incorrect and to note that the alternative methods that I suggested were published back in 1998.

I'd love to see that part of the documentation,It will be in my as well as allots others, who always have determined that accessing elements by id in such manner is only IE specific, benefit if you can point me to the right place,I tried to find that part of the spec..but could not find it help me with that charles...
Just for the refresherproblem we are talking about is

referencing an element
idValue.innerHTML
as compare to
document.getElementById("idValue").innerHTML

Charles
07-01-2003, 05:23 AM
document.getElementById() is valid W3C DOM but document.getElementById().innerHTML is not. You are supposed to use instead, as I did above, document.getElementById().replaceChild(). And I cannot show you where it doesn't say that "innerHTML" isn't there, you have to read the specification and notice for yourself its absence.

Khalid Ali
07-01-2003, 08:22 AM
You are unbelieveable Charles,If you read my first post without the urge for BS'ing the standard at me,you would hae noticed that I strictly said it was not currently standardised way to "reference" an html element with an id

Read this from my first post
"The way you are trying to reference the div element is old( and wrong in w3c ways) method of accessing elements in IE "
In absence of any valid reasoning from anybody I stick to my opinion that

idName.property

is an old IE specific way to reference elements with id

where as
document.getElementById("idName").property
is currently valid standard.

I never said any word about innerHTML being a standard or not but I guess you are not that smart to read that..darn...
what a waiste of resources this was I thought people could get something good out of this. cripes.
This thread is closed.