www.webdeveloper.com
Results 1 to 5 of 5

Thread: images in functions?

  1. #1
    Join Date
    Mar 2006
    Posts
    3

    images in functions?

    ok i definitly am doing something wrong with the assignment of mine. i am new to javascript and have been trying to complete the assignment as named on http://srufaculty.sru.edu/david.dailey/cs130/week8.htm
    but i cant seem to get the pictures to move to the right like the numbers

    here is the code i have atm could someone tell me what i messed up?

    Code:
    <HTML>
    <HEAD>
    
    <TITLE>Thing</TITLE>
    <SCRIPT LANGUAGE = "JavaScript">
    
    function move() { X3=document.form.number3.value;
    X2=document.form.number2.value;
    X1=document.form.number1.value;
    document.number3.value=X2;
    document.number2.value=X1;
    document.number1.value=X3;
    A3=document.images"Img3";
    A2=document.images"Img2";
    A1=document.images"Img1";
    document.images"Img3"=A2;
    document.images"Img2"=A1;
    document.images"Img1"=A3;
     }
    </SCRIPT>
    </HEAD>
    <BODY "this()">
    
    <FORM NAME = "form">
    
    <img src="1.gif" name = "img1">
    <img src="2.gif" name = "img2">
    <img src="3.gif" name = "img3">
    
    <INPUT value="1" NAME = "number1">
    <INPUT value="2" NAME = "number2">
    <INPUT value="3" NAME = "number3">
    
    <INPUT TYPE = "BUTTON" VALUE = "Click Here" onClick ="move()"></FORM>
    
    </BODY>
    </HTML>
    so yeah the numbers work fine but i cant do images .....please help if anyone can cause this is due by midnight and i just cant figure it out

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    These:

    A3=document.images"Img3";

    should be:

    A3=document.images.img3.src;

  3. #3
    Join Date
    Mar 2006
    Posts
    3

    still get error

    thanks :-) but now i have a different problem or maybe same one not sure

    i get a msg saying line 12 has an error "document.images.img3.src is null or not an object

    #<HTML>
    <HEAD>

    <TITLE>Thing</TITLE>
    <SCRIPT LANGUAGE = "JavaScript">

    function move() { X3=document.form.number3.value;
    X2=document.form.number2.value;
    X1=document.form.number1.value;
    document.form.number3.value=X2;
    document.form.number2.value=X1;
    document.form.number1.value=X3;
    A3=document.images.Img3.src;
    A2=document.images.Img2.src;
    A1=document.images.Img1.src;
    document.images.Img3.src=A2;
    document.images.Img2.src=A1;
    document.images.Img1.src=A3;
    }
    </SCRIPT>
    </HEAD>
    <BODY>

    <FORM NAME = "form">

    <img src="1.gif" name = "img1">
    <img src="2.gif" name = "img2">
    <img src="3.gif" name = "img3">
    <br>
    <INPUT value="1" NAME = "number1">
    <INPUT value="2" NAME = "number2">
    <INPUT value="3" NAME = "number3">

    <INPUT TYPE = "BUTTON" VALUE = "Click Here" onClick ="move()"></FORM>

    </BODY>
    </HTML>
    #

  4. #4
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Just glancing at your code the issue appears to be capitalization.

    document.images.Img3.src does not equal document.images.img3.src

    document.images.img3.src appears to be the correct one since you have <img src="3.gif" name = "img3">
    54 68 65 42 65 61 72 4D 61 79

  5. #5
    Join Date
    Mar 2006
    Posts
    3
    sweet thx that was it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles