Flic said on 11/04/2006 10:21 AM AEST:
RobG wrote:
[...]
Unless you specifically want 'block', it is better to return the display
attribute to '' (empty string) to allow it to return to the default or
whatever it has been set to by CSS or inheritance.
document.getElementById('os1').style.display = "";
Search the archives for 'display block none'.
Setting an input to display: block is likely not appropriate - the
default CSS 2 display property for an input element is inline-block:
<URL:http://www.w3.org/TR/CSS21/sample.html>
Not all browsers might implement that, so use ''.
To be honest, I hadn't even thought of using that, changed now :-)
I realised that to get what I want I would probably need the id similar
to my this.SelectedIndex, but I wouldn't know how to do this as they
are only related to the drop down box with the onChange by being on the
same form.
An option has a value and text, you can use both if you like, e.g. use
the value to determine which input to hide and the text to display
something to the user.
You can also use the form's elements collection rather than
getElementById. I have no idea what your form looks like or what you
are doing, but the following example may give you some ideas:
<script type="text/javascript">
function colourCheck(sel)
{
var form = sel.form;
if ( '5' == sel[sel.selectedIndex].value ){
form.os1.style.display = "";
form.on1.value = "Other";
} else {
form.os1.style.display = "none";
}
}
</script>
<form action="">
<select onchange="colourCheck(this);">
<option value="0">Select a value</option>
<option value="2">two</option>
<option value="5">five</option>
</select>
<input type="text" name="os1" value="os1">
<input type="text" name="on1" value="on1">
</form>
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>