Results 1 to 3 of 3

Thread: Javascript.AJAX link inside javascript dropdownmenu

  1. #1
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Javascript.AJAX link inside javascript dropdownmenu

    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.
    Last edited by Possemaster; 01-24-2008 at 04:29 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Talking

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •