viola823.DeleteThis@o2.pl wrote:
>> Nothing. It would appear that you think setting an event handler attribute
>> (here: onClick) makes its value execute automatically when the corresponding
>> element is rendered; that is not the case. The event handler code is
>> executed when the event occurs, not before. In this case, it is executed
>> when you click the button (hence "onclick").
>
> So there's no any way to do it by the buttons? :/
Of course there is a way. It is just not the way you tried. What
document.write() writes to the document is simply static text. Even if you
write a variable value, there is no magic attached to it like a reference to
the variable. You call document.write() while the document is loading, and
the value it writes is the unchanged value of the variable.
If you want to change document content you have to use appropriate
techniques. document.write() is one of them; however, If you call
document.write() after the document has loaded, it usually overwrites the
document content, so that is probably not a viable solution here. (That
is what the VK article you referred fails to explain. Never ever rely on
what is said in one of VK's articles. His notion of Voodoo programming is
unreliable at best.)
Now there are several other techniques you may try:
- modify the `value' property of a HTMLInputElement object:
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025
Example: <input ... onclick="this.form.elements["foo"].value = v;">
- modify the standards compliant node value of a text node:
http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-F68D080
Example: document.getElementById("foo").firstChild.nodeValue = v;
- modify the proprietary `innerHTML' property of an element object
http://msdn2.microsoft.com/en-us/library/ms533897.aspx
http://developer.mozilla.org/en/docs/DOM_Client_Object_Cross-Reference:DOM_HTML
Example: document.all("foo").innerHTML = v;
All of these aproaches, which may be combined, require proper feature tests
so that they do not cause a run-time error when the required properties are
not supported:
http://www.jibbering.com/faq/faq_notes/not_browser_detect.html
>> You should also validate your markup:http://vaidator.w3.org/
>
> This code was written only for example, I wouldn't place it
> elsewhere:)
It is illogical to expect non-Valid examples to work as if they were Valid.
http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann