Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 ways to Set an Attribute - Why the difference?

Status
Not open for further replies.

ruffy

Programmer
Oct 1, 2003
72
US
1) Why does the script below work,
when the commented line,
that supposedly does the same thing,
does not?
2) In fact, am I wrong, to think that the commented line
is the "more correct" way to go?
-------------------------------------------------------
var int=self.setInterval("clock()",50);

function clock() {
var t = new Date();
// document.get ElementById("clock").setAttribute("value", t);
document.getElementById("clock").value=t;
}

---------------------------------thank you-------------
 
What is the element with id [tt]clock[/tt]? An input? A div?

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Be aware that in IE, the case of the attribute you're setting matters depending on an optional 3rd parameter when using "setAttribute". Read up on that, try it, and see if it makes a difference.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 

Dwarfthrower, it's this input field:
<input type="text" id="clock" size="35" />
I hope this helps you in answering my 2 questions.

Dan - you claim, "In the case of "value" being the value to an input field, I'd always use the direct method of setting "value" - I wouldn't use "setAttribute"."

But isn't DOM scripting the way to go? What's the reason behind the claim you make?
 
It wasn't a claim - it was a statement [of how I would do it]. If it's not what you want to use, that's fine - either would work.

P.S. both with "setAttribute" and "direct" to the value property are both DOM scripting.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top