Using JS to create dynamic ALT tags?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Litron

    #1

    Using JS to create dynamic ALT tags?

    This question borders between HTML and JS.

    I would like to have one ALT tag for a Button (IMG src link) when the user
    creates an onMouseOver event and a second Alt tag displayed onMouseOver if
    that page is already current in the browser.

    Can I assign the ALT tag text to a global variable and change the value of
    the global variable when certain conditions exist, therefore having the ALT
    Tag display dynamic messages...?

    e.g.. HOME button displays: "Visit the Home page?" when the user is on a
    different page, but I'd like the message to read: "You are currently viewing
    this page!" when the Home page is current in the browser and the user
    Mouse's Over the Home button... I've already added scripts to the
    onMouseOver event that updates the status line to reflect this, but now the
    Alt text is out of sync.

    Any help would be appreciated.

    Thanx,

    Litron




  • Andrew Thompson

    #2
    Re: Using JS to create dynamic ALT tags?

    On Mon, 20 Sep 2004 10:57:21 GMT, Litron wrote:
    [color=blue]
    > This question borders between HTML and JS.[/color]

    Or maybe CSS..
    [color=blue]
    > I would like to have one ALT tag for a Button (IMG src link) when the user
    > creates an onMouseOver event and a second Alt tag displayed onMouseOver if
    > that page is already current in the browser.[/color]

    IT sounds like most of what you want done
    can be achieved using CSS on standard links,
    something like..
    <head>
    ....
    <style type='text/css'>
    li
    {
    list-style-type: none;
    white-space: nowrap;
    margin: 0px;
    padding: 5px;
    }
    a {
    display: block;
    }
    a:link, a:visited
    {
    text-decoration:none ;
    background-image: url(/link.gif);
    }
    a:active, a:hover
    {
    background-color: #662;
    color: #fff;
    text-decoration:unde rline;
    background-image: url(/active.gif);
    }
    </style>
    <head>
    <body>
    <ul>
    <li><a href='home.html '>Home</a>
    <li><a href='map.html' >Site Map</a>
    </ul>
    ....

    Completely untested, but supplied with a
    100% money back guarantee.. ;-)

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.lensescapes.com/ Images that escape the mundane

    Comment

    • SanJoseWebGuy

      #3
      Re: Using JS to create dynamic ALT tags?

      You can create a function, pass the id of the image object to it, and then have
      that function triggered with the event (mouseover) from another or same element
      on the page:
      onMouseover="ch angeAlt('id')"
      Function changeAlt(elem_ id){
      var target_element = document.getEle mentById(elem_i d);
      if(document.loc ation =="page.htm") {
      target_element. alt ="You're on This Page Already!"
      }
      }

      Comment

      • Michael Winter

        #4
        Re: Using JS to create dynamic ALT tags?

        On Mon, 20 Sep 2004 10:57:21 GMT, Litron <WTF@NoShit.c a> wrote:

        [snip]
        [color=blue]
        > I would like to have one ALT tag for a Button (IMG src link) when the
        > user creates an onMouseOver event and a second Alt tag displayed
        > onMouseOver if that page is already current in the browser.[/color]

        Unless the image changes entirely[1], the alt attribute should never
        change. The alt attribute is used to replace the image should said image
        be unrenderable. There are various reasons why that might happen.

        The alt attribute is *not* used to annotate an image - use the title
        attribute in that case.
        [color=blue]
        > Can I assign the ALT tag text to a global variable and change the value
        > of the global variable when certain conditions exist, therefore having
        > the ALT Tag display dynamic messages...?[/color]

        You can, but that won't affect the attribute. You'll need to modify the
        actual attribute:

        <img alt="<image description>" title="<initial title>"
        onmouseover="th is.title='<new title>';">
        [color=blue]
        > e.g.. HOME button displays: "Visit the Home page?" when the user is on a
        > different page, but I'd like the message to read: "You are currently
        > viewing this page!" when the Home page is current in the browser and the
        > user Mouse's Over the Home button...[/color]

        Unless you're using frames, a bad thing in itself, I don't see how this is
        a good example. The title attribute needs to read "You are currently
        viewing this page" on the home page, and "Visit the Home Page" on others.
        There's no need for scripting at all.

        [snip]

        Mike


        [1] By that, I don't mean a rollover as they tend to be variations of the
        same image (different coloured text, for example). I mean a substantial
        difference in the content of the image.

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Litron

          #5
          Re: Using JS to create dynamic ALT tags?

          Thanx Andrew, I haven't decided which route to take yet, but thanx for the
          input...

          Litron.

          -----------------
          "Andrew Thompson" <SeeMySites@www .invalid> wrote in message
          news:jamd8xe56z pu.1r4xuum8eeqt 8.dlg@40tude.ne t...[color=blue]
          > On Mon, 20 Sep 2004 10:57:21 GMT, Litron wrote:
          >[color=green]
          > > This question borders between HTML and JS.[/color]
          >
          > Or maybe CSS..
          >[color=green]
          > > I would like to have one ALT tag for a Button (IMG src link) when the[/color][/color]
          user[color=blue][color=green]
          > > creates an onMouseOver event and a second Alt tag displayed onMouseOver[/color][/color]
          if[color=blue][color=green]
          > > that page is already current in the browser.[/color]
          >
          > IT sounds like most of what you want done
          > can be achieved using CSS on standard links,
          > something like..
          > <head>
          > ...
          > <style type='text/css'>
          > li
          > {
          > list-style-type: none;
          > white-space: nowrap;
          > margin: 0px;
          > padding: 5px;
          > }
          > a {
          > display: block;
          > }
          > a:link, a:visited
          > {
          > text-decoration:none ;
          > background-image: url(/link.gif);
          > }
          > a:active, a:hover
          > {
          > background-color: #662;
          > color: #fff;
          > text-decoration:unde rline;
          > background-image: url(/active.gif);
          > }
          > </style>
          > <head>
          > <body>
          > <ul>
          > <li><a href='home.html '>Home</a>
          > <li><a href='map.html' >Site Map</a>
          > </ul>
          > ...
          >
          > Completely untested, but supplied with a
          > 100% money back guarantee.. ;-)
          >
          > --
          > Andrew Thompson
          > http://www.PhySci.org/codes/ Web & IT Help
          > http://www.PhySci.org/ Open-source software suite
          > http://www.1point1C.org/ Science & Technology
          > http://www.lensescapes.com/ Images that escape the mundane[/color]


          Comment

          • Litron

            #6
            Re: Using JS to create dynamic ALT tags?

            Thanx SanJoseWebGuy,
            I appreciate the input.

            Litron.
            ------------------
            "SanJoseWeb Guy" <sanjosewebguy@ aol.com.nospam> wrote in message
            news:2004092008 1847.03232.0000 0884@mb-m19.aol.com...[color=blue]
            > You can create a function, pass the id of the image object to it, and then[/color]
            have[color=blue]
            > that function triggered with the event (mouseover) from another or same[/color]
            element[color=blue]
            > on the page:
            > onMouseover="ch angeAlt('id')"
            > Function changeAlt(elem_ id){
            > var target_element = document.getEle mentById(elem_i d);
            > if(document.loc ation =="page.htm") {
            > target_element. alt ="You're on This Page Already!"
            > }
            > }
            >[/color]


            Comment

            • Litron

              #7
              Re: Using JS to create dynamic ALT tags?

              Thanx Michael, the "alt" tag web etiquette is noted. Thanx for the help.

              Litron
              ------------------------------------------
              "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
              news:opsemldwsi x13kvk@atlantis ...[color=blue]
              > On Mon, 20 Sep 2004 10:57:21 GMT, Litron <WTF@NoShit.c a> wrote:
              >
              > [snip]
              >[color=green]
              > > I would like to have one ALT tag for a Button (IMG src link) when the
              > > user creates an onMouseOver event and a second Alt tag displayed
              > > onMouseOver if that page is already current in the browser.[/color]
              >
              > Unless the image changes entirely[1], the alt attribute should never
              > change. The alt attribute is used to replace the image should said image
              > be unrenderable. There are various reasons why that might happen.
              >
              > The alt attribute is *not* used to annotate an image - use the title
              > attribute in that case.
              >[color=green]
              > > Can I assign the ALT tag text to a global variable and change the value
              > > of the global variable when certain conditions exist, therefore having
              > > the ALT Tag display dynamic messages...?[/color]
              >
              > You can, but that won't affect the attribute. You'll need to modify the
              > actual attribute:
              >
              > <img alt="<image description>" title="<initial title>"
              > onmouseover="th is.title='<new title>';">
              >[color=green]
              > > e.g.. HOME button displays: "Visit the Home page?" when the user is on a
              > > different page, but I'd like the message to read: "You are currently
              > > viewing this page!" when the Home page is current in the browser and the
              > > user Mouse's Over the Home button...[/color]
              >
              > Unless you're using frames, a bad thing in itself, I don't see how this is
              > a good example. The title attribute needs to read "You are currently
              > viewing this page" on the home page, and "Visit the Home Page" on others.
              > There's no need for scripting at all.
              >
              > [snip]
              >
              > Mike
              >
              >
              > [1] By that, I don't mean a rollover as they tend to be variations of the
              > same image (different coloured text, for example). I mean a substantial
              > difference in the content of the image.
              >
              > --
              > Michael Winter
              > Replace ".invalid" with ".uk" to reply by e-mail.[/color]


              Comment

              Working...