Results 1 to 7 of 7

Thread: [completly Resolved] javascript: change Picture OnClick argh.

  1. #1

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    [completly Resolved] javascript: change Picture OnClick argh.

    Okay. Why the heck won't this work for me.

    It works somewhat, but not 100%.

    What I want is an image to change based on a drop-down value.
    However, I'd be happy to just get it working for some hard-coded pictures.

    Here's what I got as a test page, I plan on populating the drop down from a database later.
    If you can supply some hints for using the value of the drop down, I'd appreciate that also.
    (this will be an ASP page)
    VB Code:
    1. <script language="JavaScript">
    2. function DoPic()
    3. {
    4.   document.PutPicHere.src="Charts\0.jpg";
    5. }
    6. </script>
    7.  
    8. <html>
    9. <body>
    10.  
    11. Hello, why don't your web page work? loser.
    12. <table>
    13. <tr>
    14.   <td><font face="arial">Choose One
    15.  
    16.     <select name="MyPix" size=1 onClick="DoPic()">
    17.       <option value="0" selected>Choice Won</option>
    18.       <option value="1" >Choice Too</option>
    19.     </select>
    20.   </td>
    21.   <td>
    22.      <img name="PutPicHere" src="Charts\1.jpg">
    23.   </td>
    24. </tr>
    25. </table>
    26.  
    27. </body>
    28. </html>


    It gets as far as replacing my current 1.jpg with a nice red 'X',
    so it's at least getting that far....

    Yes, there is a dir called Charts,
    Yes, there is a pic called 0.jpg in that dir.
    I'm running on Personal web server, but that shouldn't matter.
    I think I"m following examples I've seen for other questions...
    Last edited by JPicasso; Sep 10th, 2003 at 10:32 AM.
    Merry Christmas

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Beside your HTML being completly outdated (<font> *shudder*), here's a nice way.
    Code:
    <script language="JavaScript">
    function DoPic(s)
    {
      var val = s.options[s.selectedIndex].value;
      document.PutPicHere.src=val;
    }
    </script>
    
    <html>
    <body>
    
    Hello, why don't your web page work? loser.
    <table>
    <tr>
      <td><font face="arial">Choose One
    
        <select name="MyPix" size=1 onchange="DoPic(this)">
          <option value="somepix.png" selected>Choice Won</option>
          <option value="otherpix.png" >Choice Too</option>
        </select>
      </td>
      <td>
         <img name="PutPicHere" src="Charts\1.jpg">
      </td>
    </tr>
    </table>
    
    </body>
    </html>
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    thanks dude.

    Ya. my html is cut-and paste from my boss's old pages.

    I generally just write apps for VB for stand-alone programs,
    However, a project came up and I decided it would be best if I tried to keep my job.


    font? outdated? how else will mosaic know what characters to use?
    Merry Christmas

  4. #4

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Doh!

    I want to add a string contsant "Charts\" to the path in the function?

    like :
    VB Code:
    1. var val = 'Charts\' & s.options[s.selectedIndex].value;
    2.  
    3. OR
    4.  
    5.   document.PutPicHere.src='Charts\' & val;

    I need to just have the drop down take the name of the file, but the
    file is actually one directory in on the server.

    Unterminated string constant?

    I'm so clueless.
    Merry Christmas

  5. #5
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    & is only for comparison in JavaScript. Use a + instead.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And if you want a \ in a string you need to escape it:
    "imgs\\myimg.png"
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    I should have just been a doctor instead of this funky program stuff.

    Anyways, thanks to both of you.
    Merry Christmas

Posting Permissions

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



Click Here to Expand Forum to Full Width