Get image based on user input

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

    #1

    Get image based on user input

    I'm sorry to ask what must be a very simple question, but I just can't seem
    to get this to work.
    Right now I am using the javascript 'prompt' to enter a photoid and the
    script that I am using uses document.write
    to put the proper image on the page ....i.e. PHOTOID =".jpg"

    What I want is a simple user input text area and when submit is clicked a
    placeholder image beneath is exchanged for the proper
    image based on the user's input.
    example: User enters re4555 and the image re4555.jpg replaces the image
    nosel.jpg
    that I have created which basically says 'no image selected'.

    please,please help, this is very frustrating.
    Thank you
    webmaster@compu terholistics.co m


  • Lee

    #2
    Re: Get image based on user input

    SPEAKIT said:[color=blue]
    >
    >I'm sorry to ask what must be a very simple question, but I just can't seem
    >to get this to work.
    >Right now I am using the javascript 'prompt' to enter a photoid and the
    >script that I am using uses document.write
    >to put the proper image on the page ....i.e. PHOTOID =".jpg"
    >
    >What I want is a simple user input text area and when submit is clicked a
    >placeholder image beneath is exchanged for the proper
    >image based on the user's input.
    >example: User enters re4555 and the image re4555.jpg replaces the image
    >nosel.jpg
    >that I have created which basically says 'no image selected'.[/color]

    Is there a reason why you want to use document.write( )?
    Am I correct that you are not actually submitting a form?
    It would probably be easier and more helpful to correct your
    code than to show you new code.

    Comment

    • SPEAKIT

      #3
      Re: Get image based on user input

      here is an example of something that doesn't work.....lol

      <html>
      <head><title>Fo rmImage Test</title>
      <script>
      var selimage = NewImage();
      selimage.src = "nosel.jpg"
      function dothisnow(){
      var picid = document.getEle mentById("picid ").value;
      selimage.src = picid +".jpg";
      }
      </script>
      </head>
      <body>
      <form>
      <p align="center">
      Please Enter your Photo ID:<br>
      <input type=text id="picid" name="picid">
      <input type=button value="Click Here to See Your Photo" name="clicker"
      id="clicker" onClick=dothisn ow
      ();>
      <p align="center"> <img src="nosel.jpg" name="selimage" id="selimage">
      </form>
      </body>
      </html>
      --sorry for being an idiot.....


      Comment

      • Robert

        #4
        Re: Get image based on user input

        In article <cGp5d.107387$N p2.979@bignews4 .bellsouth.net> ,
        "SPEAKIT" <SPEAKIT@speakn et.net> wrote:
        [color=blue]
        > here is an example of something that doesn't work.....lol[/color]

        I kind of lost track of the changes that I made.
        Robert
        Try this:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head><title>Fo rmImage Test</title>
        <script type="text/javascript">

        var nasaPath = "http://spaceplace.nasa .gov" +
        "/en/educators/images/solarsystem/";

        function dothisnow(name) {
        /* Get the reference to the image. */
        var picId = document.images["imageId"];
        /* Set the name of the image.
        This causes the new image to be loaded. */
        picId.src = nasaPath + name + "_T.jpg";
        }
        </script>

        </head>
        <body>
        <form name="myForm">
        <p style="text-align: center;">
        Please Enter your Photo ID:<br>
        <input type=text
        name="picid"
        size="25">
        <br><br>
        <input type=button
        value="Click Here to See Your Photo"
        name="clicker"
        onClick=
        "dothisnow(docu ment.forms['myForm'].elements['picid'].value);">
        <br>
        <img id="imageId"
        onerror="alert( 'Could not find the image.');">
        </form>

        <p>Some values to type or to cut and paste:
        <ul>
        <li>Apollo17_Ea rth</li>
        <li>clem_full_m oon</li>
        <li>erosreconst ruct_near</li>
        <li>giotto_hall ey</li>
        <li>lspn_comet_ halley1</li>
        <li>hst_pluto_c haron</li>
        </ul>
        <p>These image are from NASA. See:<br>

        </p>
        <script type="text/javascript">
        // Fill in the default image. I am too lazy to type in the
        // full path name.

        dothisnow('Apol lo17_Earth');

        // Best to put the images at the end.
        var selimage = new Image();
        selimage.src = nasaPath + "Apollo17_Earth _T.jpg";

        var selimage = new Image();
        selimage.src = nasaPath + "clem_full_moon _T.jpg";

        var selimage = new Image();
        selimage.src = nasaPath + "erosreconstruc t_near_T.jpg";

        var selimage = new Image();
        selimage.src = nasaPath + "giotto_halley_ T.jpg";

        var selimage = new Image();
        selimage.src = nasaPath + "lspn_comet_hal ley1_T.jpg";

        var selimage = new Image();
        selimage.src = nasaPath + "hst_pluto_char on_T.jpg";

        </script>
        </body>
        </html>

        Comment

        • SPEAKIT

          #5
          Re: Get image based on user input

          You are the best!!!!!!!
          It works exactly as I needed!!!!!
          I customized a little and voila all up and running!!!

          Thank YOU thankyou THANK you THANKYOU!!!

          oh.....and I learned a lot too.......
          about syntax and the proper way to call an elementbyid and such.....

          thank you so much

          sd
          webmaster@compu terholistics.co m


          Comment

          • Robert

            #6
            Re: Get image based on user input

            "SPEAKIT" <SPEAKIT@speakn et.net> wrote in message news:<QST5d.563 79$as2.34792@bi gnews3.bellsout h.net>...[color=blue]
            >
            > thank you so much
            >[/color]

            Glad to get the positive feedback.

            Robert

            Comment

            Working...