#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    3
    Rep Power
    0

    javascript problem


    I'm doing a site where I should set a mark by the menupoint the user has selected by swapping an image.
    I've however run into problems - as I would like it to be fairly interchangeble, I have first done the following:

    var sted1 = 'document.tom_accomodation';
    var sted2 = 'document.tom_facilities';
    var sted3 = 'document.tom_restaurents';
    var sted4 = 'document.tom_banquets';
    var sted5 = 'document.tom_location';
    var sted6 = 'document.tom_rates';
    var sted7 = 'document.tom_reservation';
    var sted8 = 'document.tom_contacts';
    var sted9 = 'document.tom_news';
    var sted10 = 'document.tom_site_index';

    function menumarkering(tester) {
    //alert(tester); -- to see if the right variable is assigned, which it is
    //document.tom_news.src = 'grafik/kn_idikator.gif'; -- to test if the error is somewhere else in the code, as this is what the code should do
    tester.src = 'grafik/kn_idikator.gif'; // this is supposed to change the image in document.theVariable.src to 'grafik/kn_idikator.gif'

    }

    <a href="javascript:menumarkering(sted9);">the link</a>

    The problem seems to be that I just seem to assign 'grafik/kn_idikator.gif' to be the variable "tester" instead of changing the image.

    Does anyone have an idea on how to solve this?

    Hope it makes sense :-)

    TIA,
    Peter
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    Assigning the value is the whole point of arguments.

    function changeImage(newSrc) {
    theImg.src=newSrc;
    }
    changeImage('source of the image')
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    3
    Rep Power
    0
    Thanks for your reply, DJdrenaline!
    But, if I understand it correctly, it's the opposite of what I'm trying to do;
    I'm trying to make "theImg" and not "newSrc" the changeble part, as it is the same image which should be used to mark which menu-point the user has selected - but I would like to make a function, which can be used for all the menupoints, meaning:
    - if I click menupoint 1, I call function changeImage(sted1), which says document.tom_accomodation.src = 'grafik/kn_idikator.gif';
    - if I click menupoint 5, I call function changeImage(sted5), which says document.tom_location.src = 'grafik/kn_idikator.gif';

    Hope that this clear things up ;-)

    Peter
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    If i understand correctly, this is what you need:

    <script language="javascript">

    var sted1 = 'document.tom_accomodation';
    var sted2 = 'document.tom_facilities';
    var sted3 = 'document.tom_restaurents';
    var sted4 = 'document.tom_banquets';
    var sted5 = 'document.tom_location';
    var sted6 = 'document.tom_rates';
    var sted7 = 'document.tom_reservation';
    var sted8 = 'document.tom_contacts';
    var sted9 = 'document.tom_news';
    var sted10 = 'document.tom_site_index';

    function images(img) { // put sted1,sted2, etc, as the argument
    document.images["image name"].src=img;
    }

    </script>
    <body>
    <a href="javascript:images(sted5)">Sted5</a>
    <a href="javascript:images(sted8)">Sted8</a>
    </body>


    Good luck.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    BTW, there is no space between the javascript in the <a> tag. (javascript: ) The forum does it automatically.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    3
    Rep Power
    0
    var javascript_god = "DJdrenaline";!!!!!

    After tweaking a bit on your answer, I finally got it to work.
    Thanks a lot for your help!

    Peter

IMN logo majestic logo threadwatch logo seochat tools logo