Click to See Complete Forum and Search --> : Javascript help pls


esk
September 22nd, 2005, 06:15 AM
I have this code and i have been trying to get it to work for a while now......

I am not an advanced programmer by a long shot but i am trying.........

i am trying to show a table once a DDlist item has been selected (onchange)

this is the Jscript.

<script type="text/javascript" language="Javascript">
function Navlink() {
var list = document.myform.ddOffices;
var listValue = list.options[list.selectedIndex].value;
listValue.style.display='block';
}
</script>

which i want to activate this:

table cellpadding="0" cellspacing="0" border="0" width="50%">
<tr>
<td id="Altrincham" style="display: none">
<table class="tableborder" width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td nowrap class="bodyfont" colspan="2">ALTRINCHAM</td>
</tr>


myform is the form name and ddoffices is the DDlistmenu's ID:
<select name="ddOffices" class="selecttag" id="ddOffices" onchange='Navlink()'>

any ideas??

i get style is null or not an object

esk
September 22nd, 2005, 06:42 AM
0.o

wow......................
>>>>FAAAAAANTASTIC<<<<

works like a charm, many thanks olivthill.......
you will be added to my xmas card list.....

olivthill
September 22nd, 2005, 07:33 AM
Yes, listValue is not an object, it is a value, therefore a string.

You should do something like:
<head>
...
obj=document.getElementById('my_table');
obj.style.display='block';
</head>
<body>
...
<table .... id="my_table">
...
</table>
...
</body>

esk
September 22nd, 2005, 10:03 AM
ok nother quick question:

<script type="text/javascript" language="Javascript">
function Navlink() {
var list = document.myform.ddOffices;
var listValue = list.options[list.selectedIndex].value;
obj=document.getElementById(listValue);
if (obj.style.display=='block') {
obj.style.display='none';
}
else {
obj.style.display='block';
}
}
</script>

this works to a degree but i need to hide the table that has been displayed if another selection in the list is made.

There are gonna be about 20 tables with the ID="office name" style="display: none;"

and each needs to be hidden and displayed on the onchange event in the ddList