Newbie question - only first word of alt tag displays!

Discussion in 'Javascript' started by Chris Curtis, May 17, 2006.

  1. Chris Curtis

    Chris Curtis Guest

    Actually I'm not sure even newbie qualifies! I originally posted this in the
    Java help group!!
    I'm trying to adapt an ad rotating script I found on the net yesterday.
    The author's contact details no longer work.

    All I've done is add a variable to create a related alt tag.
    However, all that displays is the first word!
    I suspect it is something simple.

    Remember, I'm a total novice!

    Regards
    Chris Curtis

    The page can be viewed at
    http://www.brss.org.uk/indexbannerscrpt.htm

    The relevant part of the script:

    var refreshTime = 5000;
    var numAds = 3;

    function makeAd() {
    this.width = ''
    this.height = ''
    this.src = ''
    this.href = ''
    this.alt = ''
    this.mouseover = ''
    }

    var ads = new Array()
    for(var i = 1; i <= numAds; i++) { ads = new makeAd() }
    i = 1;

    ads.width = "200"
    ads.height = "130"
    ads.src = "images/blackcatcomputers.jpg"
    ads.href = "http://www.blackcatcomputers.co.uk"
    ads.alt = "Black Cat Computers Tel 01527 889584"
    ads.mouseover = "Black Cat Computers Tel 01527 889584"
    i++

    DETAILS OF OTHER TWO ADS GO HERE

    var myCode = '';
    do {
    var n= Math.floor(Math.random() * (numAds + 1) + 1);
    } while(n > numAds);
    var current_ad = n;
    myCode = getCode(n);

    function getCode(adNumber){
    var tempCode = ""
    tempCode += ('<a href="'+ ads[adNumber].href + ' "target=_blank"' +
    ads[adNumber].width +'" \n')
    tempCode += ('onMouseOver="status=\''+ ads[adNumber].mouseover +'\';return
    true" \n')
    tempCode += ('onMouseOut="status=\'\'"> \n')
    tempCode += ('<img src="' + ads[adNumber].src + '" alt=' +
    ads[adNumber].alt + '" width=' + adsadNumber].width)
    tempCode += (' onLoad="setTimeout(\'newAd();\',' + refreshTime + ');"')
    tempCode += ('\n height=' + ads[adNumber].height + ' border=0 >')
    tempCode += ('</a>')
    return tempCode;
    }
    Chris Curtis, May 17, 2006
    #1
    1. Advertising

  2. Chris Curtis wrote:
    <snip>
    > tempCode += ('<img src="' + ads[adNumber].src + '" alt=' +

    ^
    There is no opening double quote in your string literal.

    > ads[adNumber].alt + '" width=' + adsadNumber].width)

    <snip> ^^
    - but there is a closing double quote. That is the sort of thing that
    will throw a browser off. As unquoted attribute values may not contain
    spaces without the quote the first space defines the end of the ALT
    _attribute_ value, and so you only see the first word.

    Richard.
    Richard Cornford, May 17, 2006
    #2
    1. Advertising

  3. Chris Curtis

    Chris Curtis Guest

    "Richard Cornford" <> wrote in message
    news:...
    > Chris Curtis wrote:
    > <snip>
    >> tempCode += ('<img src="' + ads[adNumber].src + '" alt=' +

    > ^
    > There is no opening double quote in your string literal.
    >
    >> ads[adNumber].alt + '" width=' + adsadNumber].width)

    > <snip> ^^
    > - but there is a closing double quote. That is the sort of thing that
    > will throw a browser off. As unquoted attribute values may not contain
    > spaces without the quote the first space defines the end of the ALT
    > _attribute_ value, and so you only see the first word.
    >
    > Richard.


    Many thanks Richard!

    Chris
    Chris Curtis, May 17, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    1
    Views:
    3,000
    Ken Cox [Microsoft MVP]
    Nov 23, 2003
  2. Chumley Walrus
    Replies:
    1
    Views:
    12,177
    =?Utf-8?B?QnJpYW4gQnJvd24=?=
    Dec 16, 2004
  3. Sparky Arbuckle

    Only First Shopping Cart Item Displays

    Sparky Arbuckle, Feb 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    301
    Sparky Arbuckle
    Feb 20, 2005
  4. shruds
    Replies:
    1
    Views:
    792
    John C. Bollinger
    Jan 27, 2006
  5. =?iso-8859-1?Q?Marcel_St=F6r?=

    alt attribute for input tag

    =?iso-8859-1?Q?Marcel_St=F6r?=, Nov 28, 2003, in forum: HTML
    Replies:
    10
    Views:
    10,818
    Sid Ismail
    Nov 28, 2003
Loading...

Share This Page