Click to See Complete Forum and Search --> : Strings as document element names


ugh_bough
09-11-2003, 02:51 PM
Hi there,

i generate javascriptcode with php. i want to use strings as elementnames. ie


<script>
function change_open (name) {
dosument.name.style.display='';
}
</script>

<li name='thisname' onclick='change_open(this.name)'>Test</li>
<ul id='thisname' style='display:none'>
.
.
.


in this example the unsorted list is hidden at the beginning. when the list item is clicked, it should be displayed.

is it possible to use strings this waY?

thanx, ugh_bough

Fang
09-12-2003, 06:55 AM
No, anyway Netscape has a problem with the attribute name
With IE this works:
document.getElementById(name).style.display='block';

A better solution:
<script type="text/javascript">
<!--
function change_open (obj) {
var ShowMe=obj.getAttribute("name");
document.getElementById(ShowMe).style.display='block';
}
//-->
</script>

</head>
<body>

<li name='thisname' onclick='change_open(this)'>Test</li>
<ul id='thisname' style='display:none'>
<li>hello</li>
</ul>
</body>

ugh_bough
09-12-2003, 11:16 AM
thanx for your help:)