javier,
The SELECT element directly supports only the Blur, Change and Focus events
(some browsers support additional events but these are the only ones
guaranteed to work).
That's one reason why nothing happens.
The other reason that the correct object reference for the selected OPTION
from a SELECT named "mySelect" in a form named "myForm" is:
var myOptionValue=document.myForm.mySelect.options[document.myForm.mySelect.selectedIndex].value;
Some browsers support shortcuts such as the one you're trying to use, but
that's non-spec behavior and can't be trusted.
But even if you used the onChange event handler and referenced the selected
option correctly, either nothing would happen, or else you'd just make a
mess out of your page (depending on browser/version). Here's why:
You can't just document.write() to an existing page like you're trying to
do. In older (version<=3) browsers, basically all you can do is to
document.open(), document.write(), and document.close() the entire page --
you could use frames and either load a new page or rewrite the HTML for the
page in one of the frames. In IE4+ and NS6+ you can set the innerHTML
property of an existing element equal to a string containing the desired
HTML. In NS4, you can document.open()/document.write()/document.close() a
Layer (DIV or LAYER tag).
Here's something that might get you started:
<!-- Suppose you have an absolutely positioned DIV -->
<div style="position:absolute;left=100px;top=100px">Here's a DIV.</div>
<!-- end of HTML -->
// Now for some script code
var myHtmlTable="<table><tr><td>This is a one-celled table.</td></tr></table>";
var myEl=null;
if(document.layers)
{
my El=document.layers["myDiv"].document;
with(myEl)
{
open();
write(myHtmlTable);
close();
}
}
else
{
if(document.getElementById)
{
myEl=document.getElementById("myDiv");
}
else
{
if(document.all)
{
myEl=document.all["myDiv"];
}
}
if(myEl!=null)
{
myEl.innerHTML=myHtmlTable;
}
}
// end script code
For IE4+ and NS6+ the element can be almost any HTML tag, and doesn't have
to be absolutely positioned.
In all cases, the resulting HTML must be valid and well-formed, e.g. you
can't just glomm a fifth table cell into the row of a table where all the
other rows have only four cells each.
Hope this helps!
jon.
javascript digest wrote:
> Subject: <select> appearing onClick
> From: "javier" <javiguillen@h...> Date: Mon, 23 Apr 2001 15:57:29
> X-Message-Number: 4
>
> im working on this script that includes a <Select> option and im trying to
> figure out how to make ANOTHER select appear or not depending on the
> option selected on the first one (which is called "DistribuitorORclient"
> in the form "add")... they should both be on a table, thus, i developed
> this simple script.:
>
> function verify_DistribuitorORclient()
> {
> if (document.add.DistribuitorORclient.value == "Distribuitor")
> // alert ('it is a distribuitor');
> document.write('<td>');
> document.write('clients - distribuitors');
> document.write('</td>');
>
>
> }
>
> and then in the table, after a </td> tag i wrote:
>
> <script> verify_DistribuitorORclient()
> </script> so i'd write the <td> tags and the message.. just for testing...
>
> but it's doing nothing!!! any ideas??
>
> javier g.
>
> ----------------------------------------------------------------------
--
jon stephens
<jstephens@m...>
web developer
micro-cap news network
http://www.mcnn.net/
scottsdale az
+1.480.922.3600
*The views expressed in this message do
not necessarily reflect those of MCNN, etc.*