In <3t************@uni-berlin.de>, =?ISO-8859-1?Q?G=E9rard_Talbot?= <ne***********@gtalbot.org> writes:
jo******@nospam.com.au a écrit : I want to produce a trivial demonstration of dynamic modification.
I thought that pressing a button might change its color.
I studied O'Reillys books and successfully created the button with a fancy
style, but the onclick fails to do anything no matter what permutation of
parameters I try.
<input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR" onclick="xyz.setAttribute('style=backgroundColor': cyan);"/>
Can you point me in the right direction?
You should always quote attribute values.
You should give preferences to using id attribute for elements and name
for form input controls. This is for later script access to such
elements. For forms input controls:
document.forms["FormName"].FormInputControlName
will give access to such form input control.
For other elements:
document.getElementById(id_attribute_value)
where id_attribute_value is the string value of the id attribute value.
For more on all this:
http://www.mozilla.org/docs/web-deve...tml#dom_access
Merci Gérard for your pointers. I employed them to enhance my trivial
forms code demonstration (which has to be independent of web and mail servers)
but my javascript code (which works) is not identical to any of the samples I
read.
Does my code look OK or does it contain deprecated items?
<form name="f1">
Select colour
<INPUT TYPE="RADIO" NAME="radioSet" VALUE="Yellow">Yellow
<INPUT TYPE="RADIO" NAME="radioSet" VALUE="Cyan">Cyan
<INPUT TYPE="reset" VALUE="RESET" /><Br>
<input type=button style=background-color:magenta;color:blue;font-family:Arial;font-style:italic;font-weight:bold value="CHANGE COLOUR" onclick="if (document.forms['f1'].radioSet[0].checked){this.style.backgroundColor = 'yellow'} else if (document.forms['f1'].radioSet[1].checked){this.style.backgroundColor = 'cyan'} else {this.style.backgroundColor = 'magenta'};"/><Br>
</form>