Board Logo

Run javascript from menu item choice.
jem - 9/15/2009 at 10:52 AM

OK, either my programming is a bit rusty (highly possible) OR I'm missing something.

What I am trying to do is clean up our website from using iFrames to CSS.

I have setup a 3 column, header footer layour using CSS DIV's.
What I am now trying to do is make the menu item choices only change the CONTENT DIV. I tried a simple javascript as per the example in the documentation and it does not run.

Here is the code for the main page

<div id="Header">
<div align="center">Header
<script type="text/javascript">
<!--
new menu (MENU_ITEMS, MENU_TPL);
//-->
</script>
</div>
</div>
<div class="threecol">
<div class="colmid">
<div class="colleft">
<div class="col1">
<!-- Column 1 start -->
<h2>Main</h2>
<!-- Column 1 end -->
</div>
<div class="col2">
<!-- Column 2 start -->
<?php
include('sidebar_left.php');
?>
<!-- Column 2 end -->
</div>
<div class="col3">

<!-- Column 3 start -->
<?php
include('sidebar_right.php');
?>

<!-- Column 3 end -->
</div>
</div>
</div>
</div>
<div id="footer">
<h2>Footer</h2>
</div>

And here is the item.js code

/* Tigra Menu items structure */
var MENU_ITEMS = [
['Home', null],
['Products', null, null,
['test div link', 'javascript:action("Hello World!");'],
['test mail to', 'mailto:[email protected]']
]
];


The mailto works but the javascript does not.
When I goto click on the 'test div likn' I get no response.
The status bar shows 'javascript:action(' and that is all. it should show javascript:action("Hello World!");

Any help would be appreciated
Thanks


jem - 9/15/2009 at 11:56 AM

OK, I changed the text slightly to swap ' and " as follows

ORIGINAL LINE

['test div link', 'javascript:alert("Hello World!");'],


NEW LINE

['test div link', "javascript:alert('Hello World!');"],

and now it works fine.

Any suggestions as to why?


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/