View Full Version : Resolved what is wrong with this?

06-09-2011, 01:48 AM
First, I am new to javascript... I've been trying to get help on a dynamic menu but no one ever seems to respond... So I will start with the pieces... I do not understand why this chunk of code is not working... All i have is a div and the script is simply supposed to make the div have a new size...
here is the script...

<script type="text/javascript">
var stretch = 200;
function Expand(index) {
var dname = "menu" + index;
document.getElementById(dname).style.width = stretch+'px';

here is the styling

<style type="text/css">
.show{height:20px; width:100px; display:block; background:lightgreen;}

and here is the simple html

<div id="menu1" class="show" onclick="runExpand(1)"></div>

Logic Ali
06-09-2011, 02:24 AM
Where is your runExpand function?

Try using the error console.

06-09-2011, 02:57 AM
doesnt the onclick event of onclick="runExpand(1)" call the function of Expand(index)

I built this off of a reference demo I found (it was for a js accordion) and they had a function "function Accordion(index){etc}
and they had a onclick="runAccordion(1)".... is this the wrong way to do it?
my understanding was that it would then call the function and in essence "ignore" the "run" part and use the "run" part as a directive as to what to do... this logic is wrong?

06-09-2011, 08:29 AM
if you call the function runExpand(), it will look for a function called runExpand, what you want to do is just call the expand() function directly.

in your reference, i would assume that runAccordian() is a separate function that does something, then itself calls accordian().

06-09-2011, 08:43 PM
that did it :D thanx for clarifying the "runExpand" "Expand"