SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not sure where to place the link code in my javascript? Novice

    Hi all I need a little help applying a basic link to my js output:

    I need to fit <a href="redir.php?url=http:// on 'web' below:

    Code JavaScript:
    ..
    var html = "<b>" + name + "</b> <br/>" + address + "<br/><br/>" + web;

    I have tried:

    Code JavaScript:
    var html = "<b>" + name + "</b> <br/>" + address + "<br/><br/>" '<a href="http://(' + web +')"></a>';

    ..but my map just goes missing? Can anybody help? Thanks

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to mix up double quotes with simple quotes.

    The Error Console in Firefox will tell you exactly where this error occurred.

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Pepejeria

    error 1
    Code JavaScript:
    Error: missing ; before statement
    Source Code:
          var html = "<b>" + name + "</b> <br/>" + address + "<br/><br/>" '<a href="http://(' + web +')">' + web + '</a>';

    .. when I put ; after the last two <br/><br/>"; '<a .. like the report says it then stops executing the link part?

    error 2
    Code JavaScript:
    Error: load is not defined
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    Can anybody help?

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're missing a + before the anchor bit.

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the error occurs after the last two brakes. Why do you close the String there? There is no need to close it. Also, you sometimes use double quotes (the first b tag) and sometimes single quotes (when closing the a tag at the end). This makes it more confusing for yourself.

    But again, there is no need to close the String after the two brakes. There is also no need to have a single quote before the starting a tag.

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks raffles + done the job almost..

    Code JavaScript:
    var html = "<b>" + name + "</b> <br/>" + address + "<br/><br/>" + '<a href="http://' + web +'"> + web + </a>';

    .. with the above I can now get a link but instead of the URL getting shown in the browser it shows + web + but the external link works fine which shows and links to www.example.com when I roll over so how do I get www.example.com to replace + web +?

    Why do you close the String there? it's what the FF error report said, like I said JavaScript novice thanks

    Does the above look right then now? Could you please modify it to fix the problem, regarding the ' and " whats the benefit of one from the other?

    This is a bit more of my code so your saying it's best to use ' ' like I have with my side_bar_html below? thanks guys

    Code JavaScript:
    function createMarker(point, name, address, web, type) {
          var marker = new GMarker(point, customIcons[type]);
          var html = "<b>" + name + "</b> <br/>" + address + "<br/><br/>" + '<a href="http://' + web +'">+ web +</a>';
          GEvent.addListener(marker, 'click', function() {
            marker.openInfoWindowHtml(html);
          });
     
    	  gmarkers[i] = marker;
    	  side_bar_html += '<a href="javascript:myclick(' + i + ')"><strong>' + name + '</strong></a><br>';
    		i++;
     
          return marker;
        }

    Cheers

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you look at the line of code you posted, you'll notice the blue stuff is strings and the black stuff is variables and operators. Thus where it says + web + it is just being outputted as a string, that's why it's blue. To display "example.com" instead of "+ web + " you need to close the string starting with '"> and then start it again after web + (since you want </a> as a string - it is meaningless in Javascript). Like Pepejeria says, you should try being more consistent with your use of single and double quotes (like with the sidebar thing). If you want to output a single/double quote in a single/double quoted string (respectively) you must escape it using the backslash (\) immediately before it.

    I'm not going to write the code for you, though, because I think this is pretty basic and you need to learn it for yourself.

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks working great now:

    Code JavaScript:
    var html = '<b>' + name + '</b><br/>' + address + '<br/><br/>' + '<a href="http://' + web +'">' + web + '</a>';


    Thanks for pointing the problems out and advice guys


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
  •