Page 1 of 1

help with onChange document.write

Posted: Mon May 03, 2010 12:19 pm
by me666
Hey all, i'm getting to grips with php but have a small javascript problem. I have a form below and need a little help adding an onChange=document.write for the dropdown box. I have added in the code where I want what values but am unsure as to how to implement it.

Code: Select all

<form action="?0&posts=5" method="post">
Update: <select name="color">
<option value="blue">Text Colour</option>
<option value="blue">Default</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="purple">Purple</option>
<option value="orange">Orange</option>
<option value="yellow">Yellow</option>
<option value="brown">Brown</option>
<option value="black">Black</option>
</select>
//here I would like <font color="selected option value"> and by default <font color="blue"> //
<input type="text" name="update" value="Update text here...">
</font>
<input type="submit" name="upst" value="Update">
</form> 
Can anyone give me some advice on how to achieve this please? :)
Thanks all

Re: help with onChange document.write

Posted: Mon May 03, 2010 1:42 pm
by kaszu
When onchange event occurs use

Code: Select all

document.getElementById
to get <font> element and

Code: Select all

HERE_RETURNED_ELEMENT.setAttribute('color', ...);
method of element to change "color" attribute. You can wrap that text in P or DIV and also use document.getElementId and

Code: Select all

HERE_RETURNED_ELEMENT.style.display = 'block';
to show that text if it's not visible when page loads.

Re: help with onChange document.write

Posted: Mon May 03, 2010 2:34 pm
by me666
thanks for the reply, but i'm not familiar with javascript and so this help has really confused me :?
is there any chance you could show me with a small example please?