PDA

View Full Version : Javascript.AJAX link inside javascript dropdownmenu



Possemaster
01-24-2008, 02:29 PM
Hi everybody,

i have a drop down menubar that is writen in javascript.
I also have some ajax code to dynamicly load an external html inside the content div.

The both work, but i cant use my link for dynamicly load an external htm inside the javascript dropdown.

example:

ajax href to load data:
javascript:ajaxpage('home.htm', 'content') works in plain html links.

inside the dropdown.js is a list of links with this code:
var menu2=new Array()
menu2[0]='<a href="sample.htm">Ministry</a>' loads sample.htm
menu2[1]='<a href="#">Us</a>'
menu2[2]='<a href="#">Friends</a>'
menu2[3]='<a href="#">Statement</a>'

what i want is
menu2[0]='<a href=javascript:ajaxpage('home.htm', 'content')>Ministry</a>'

but then the drop down doesn´t load.

who can help me??

here is my url where the content is on: http://www.roytimmermans.be
the home/contact and encouragement buttons work now, because they are no javascript, the roll overs work also because i deleted the link inside the javascript.

jscheuer1
01-25-2008, 05:53 AM
There could be other problems, but assuming everything else works, it looks like a simple case of improperly nested delimiters ( " and ', in this case).

If you do this:


menu2[0]='<a href=javascript:ajaxpage('home.htm', 'content')>Ministry</a>'

When the script parser gets to the red highlighted ' mark, it thinks it is at the end of the menu2[0] string, but there is stuff after that doesn't fit into what it is expecting to see next, so it really gets confused and gives up.

Now, nested delimiters may be escaped (ex: \'), and you have both " and ' to work with, and I like to delimit the href, and I don't like the results of the javascript: convention in certain cases, so I would write it like so:


menu2[0]='<a href="home.htm" onclick="ajaxpage(this.href, \'content\');return false;">Ministry</a>'

Possemaster
01-25-2008, 09:46 AM
thanks jscheuer1 , i tested it and it woks perfect.

I allready wrote a new dropdown menu in html and css, with ul and li items.

But you taught me that nested delimiters may be escaped. so i can use javascript links inside an other javascript.

thanks