select box to control image source

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

    #1

    select box to control image source

    When I put the following code on a page the image on the page changes
    when I mouse over the links. Now I was thinking I could instead create
    a popup menu to change the image on the page, see second code sample.
    But it doesn't work. What am I doing wrong? Or is this just not
    possible? What am I missing? (Must be something obvious:-/)
    Any help appreciated..

    sample 1
    ===========
    <a href='#' onmouseover="do cument.pict.src ='pict_1.jpg'"> Picture
    1</a><br>
    <a href='#' onmouseover="do cument.pict.src ='pict_2.jpg'"> Picture
    2</a><br>
    <a href='#' onmouseover="do cument.pict.src ='pict_3.jpg'"> Picture
    3</a><br>

    <img name='pict' src='initial.jp g border='0'>
    ===========

    sample 2
    ===========

    <select name='selectIma ge'>"
    <option value='pict_1'
    onchange="docum ent.pict.src='p ict_1.jpg'">Pic ture 1</option>
    <option value='pict_2'
    onchange="docum ent.pict.src='p ict_2.jpg'">Pic ture 2</option>
    <option value='pict_3'
    onchange="docum ent.pict.src='p ict_3.jpg'">Pic ture 3</option>
    </select>

    <img name='pict' src='initial.jp g border='0'>
    ===========

    --
    Bart
  • Lee

    #2
    Re: select box to control image source

    Bart said:[color=blue]
    >
    >When I put the following code on a page the image on the page changes
    >when I mouse over the links. Now I was thinking I could instead create
    >a popup menu to change the image on the page, see second code sample.
    >But it doesn't work. What am I doing wrong? Or is this just not
    >possible? What am I missing? (Must be something obvious:-/)
    >Any help appreciated..[/color]

    You won't get very far by guessing.
    You should find a book or online tutorial.
    The FAQ for this newsgroup will help you to get started.


    Since there's no way for the user to change the value
    of an option, options don't have an onchange handler.
    The Select object is what has the onchange handler.

    Comment

    • Bart

      #3
      Re: select box to control image source

      In article <cbal3m0i43@drn .newsguy.com>, Lee <REM0VElbspamtr ap@cox.net>
      wrote:
      [color=blue]
      > Bart said:[color=green]
      > >
      > >When I put the following code on a page the image on the page changes
      > >when I mouse over the links. Now I was thinking I could instead create
      > >a popup menu to change the image on the page, see second code sample.
      > >But it doesn't work. What am I doing wrong? Or is this just not
      > >possible? What am I missing? (Must be something obvious:-/)
      > >Any help appreciated..[/color]
      >
      > You won't get very far by guessing.
      > You should find a book or online tutorial.
      > The FAQ for this newsgroup will help you to get started.
      > http://www.jibbering.com/faq/[/color]

      Thanks for the link. I am aware of the point you make.
      [color=blue]
      > Since there's no way for the user to change the value
      > of an option, options don't have an onchange handler.
      > The Select object is what has the onchange handler.[/color]

      That is exactly the kind of clue I was looking for!
      Thank you,

      --
      Bart

      Comment

      • Stuart Palmer

        #4
        Re: select box to control image source

        <select name='selectIma ge' onchange="docum ent.pict2.src=t his.value;">
        <option value='pict_1.j pg';">Picture 1</option>
        <option value='pict_2.j pg';">Picture 2</option>
        <option value='pict_3.j pg';">Picture 3</option>
        </select>

        <img name='pict2'
        src='http://us.i1.yimg.com/us.yimg.com/i/us/pi/50/2004/06/nelly_1.jpg'
        border='0'>

        "Bart" <bart@thuis.bla > wrote in message
        news:2306200402 58192226%bart@t huis.bla...[color=blue]
        > When I put the following code on a page the image on the page changes
        > when I mouse over the links. Now I was thinking I could instead create
        > a popup menu to change the image on the page, see second code sample.
        > But it doesn't work. What am I doing wrong? Or is this just not
        > possible? What am I missing? (Must be something obvious:-/)
        > Any help appreciated..
        >
        > sample 1
        > ===========
        > <a href='#' onmouseover="do cument.pict.src ='pict_1.jpg'"> Picture
        > 1</a><br>
        > <a href='#' onmouseover="do cument.pict.src ='pict_2.jpg'"> Picture
        > 2</a><br>
        > <a href='#' onmouseover="do cument.pict.src ='pict_3.jpg'"> Picture
        > 3</a><br>
        >
        > <img name='pict' src='initial.jp g border='0'>
        > ===========
        >
        > sample 2
        > ===========
        >
        > <select name='selectIma ge'>"
        > <option value='pict_1'
        > onchange="docum ent.pict.src='p ict_1.jpg'">Pic ture 1</option>
        > <option value='pict_2'
        > onchange="docum ent.pict.src='p ict_2.jpg'">Pic ture 2</option>
        > <option value='pict_3'
        > onchange="docum ent.pict.src='p ict_3.jpg'">Pic ture 3</option>
        > </select>
        >
        > <img name='pict' src='initial.jp g border='0'>
        > ===========
        >
        > --
        > Bart[/color]


        Comment

        • Bart

          #5
          Re: select box to control image source

          In article <f_9Cc.11$kX3.4 @newsfe6-win>, Stuart Palmer
          <stuartglenpalm er@ntlworld.com > wrote:
          [color=blue]
          > <select name='selectIma ge' onchange="docum ent.pict2.src=t his.value;">
          > <option value='pict_1.j pg';">Picture 1</option>
          > <option value='pict_2.j pg';">Picture 2</option>
          > <option value='pict_3.j pg';">Picture 3</option>
          > </select>
          >
          > <img name='pict2'
          > src='http://us.i1.yimg.com/us.yimg.com/i/us/pi/50/2004/06/nelly_1.jpg'
          > border='0'>[/color]

          Thanks Stuart, with the clue posted earlier I figured it out. Cool
          picture though :-)

          --
          Bart

          Comment

          • Grant Wagner

            #6
            Re: select box to control image source

            For browsers where it's possible <img> tag names aren't properties of the
            document object, you're probably better off using the images[] collection.
            And for browsers that don't support retrieving the value on a <select>,
            you're better off using the method shown in the FAQ: <url:
            http://jibbering.com/faq/#FAQ4_13 />

            Putting the above to use results in:

            <
            select
            name="selectIma ge"
            onchange="

            document..image s['pict2'].src=this.optio ns[this.selectedIn dex].value;
            "[color=blue]
            >[/color]

            Broken onto multiple lines for readability.

            Stuart Palmer wrote:
            [color=blue]
            > <select name='selectIma ge' onchange="docum ent.pict2.src=t his.value;">
            > <option value='pict_1.j pg';">Picture 1</option>
            > <option value='pict_2.j pg';">Picture 2</option>
            > <option value='pict_3.j pg';">Picture 3</option>
            > </select>
            >
            > <img name='pict2'
            > src='http://us.i1.yimg.com/us.yimg.com/i/us/pi/50/2004/06/nelly_1.jpg'
            > border='0'>
            >
            > "Bart" <bart@thuis.bla > wrote in message
            > news:2306200402 58192226%bart@t huis.bla...[color=green]
            > > When I put the following code on a page the image on the page changes
            > > when I mouse over the links. Now I was thinking I could instead create
            > > a popup menu to change the image on the page, see second code sample.
            > > But it doesn't work. What am I doing wrong? Or is this just not
            > > possible? What am I missing? (Must be something obvious:-/)
            > > Any help appreciated..
            > >
            > > sample 1
            > > ===========
            > > <a href='#' onmouseover="do cument.pict.src ='pict_1.jpg'"> Picture
            > > 1</a><br>
            > > <a href='#' onmouseover="do cument.pict.src ='pict_2.jpg'"> Picture
            > > 2</a><br>
            > > <a href='#' onmouseover="do cument.pict.src ='pict_3.jpg'"> Picture
            > > 3</a><br>
            > >
            > > <img name='pict' src='initial.jp g border='0'>
            > > ===========
            > >
            > > sample 2
            > > ===========
            > >
            > > <select name='selectIma ge'>"
            > > <option value='pict_1'
            > > onchange="docum ent.pict.src='p ict_1.jpg'">Pic ture 1</option>
            > > <option value='pict_2'
            > > onchange="docum ent.pict.src='p ict_2.jpg'">Pic ture 2</option>
            > > <option value='pict_3'
            > > onchange="docum ent.pict.src='p ict_3.jpg'">Pic ture 3</option>
            > > </select>
            > >
            > > <img name='pict' src='initial.jp g border='0'>
            > > ===========
            > >
            > > --
            > > Bart[/color][/color]

            --
            | Grant Wagner <gwagner@agrico reunited.com>

            * Client-side Javascript and Netscape 4 DOM Reference available at:
            *


            * Internet Explorer DOM Reference available at:
            *
            http://msdn.microsoft.com/workshop/a...ence_entry.asp

            * Netscape 6/7 DOM Reference available at:
            * http://www.mozilla.org/docs/dom/domref/
            * Tips for upgrading JavaScript for Netscape 7 / Mozilla
            * http://www.mozilla.org/docs/web-deve...upgrade_2.html


            Comment

            Working...