Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Saskatoon SK Canada
    Posts
    174
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Lightbulb calling a function

    Hi.

    I know how to call a function this way: example.

    <script>
    myfunction('my_paramenter');
    </script>


    This isn't so easy. I want to call a function depending on the value of a menu dropdown option. I'm sending the function call to another function, mychange(), to call it. Confused? Ok here is the code


    <form name="print">
    <select name="mypics" size=1 class="imp" onChange="mychange(this.options[this.selectedIndex].value)">
    <option value="aye('pic3','nicola.gif','images/graphics/nicola_large.gif')">PickNic's Bakery
    <option value="aye('pic21','titanic.jpg','images/graphics/titanic_large.jpg')">Atlantis VHS Movie Cover Demo
    <option value="aye('pic22','ecm.gif','images/graphics/every_canadian_magazine.pdf')">Every Canadian Magazine Demo
    </select>
    </form>


    function aye(thelayer,theimg,thelink) {

    var x='<a href="'+ thelink +'" target="_blank"><img src=\"images/graphics/'+theimg+'\" width=300 border=0></a>';

    for (var i=0; i<document.layers.length; i++) {
    document.layers[i].visibility="hide";
    }
    document.layers[thelayer].document.open();
    document.layers[thelayer].document.write(x);
    document.layers[thelayer].document.close();
    }



    function mychange(perameters?) {

    ? yeah that's as far as I got.

    }


    How do I get it from being an <option value> to calling a function?
    Last edited by dreamingdigital; 03-19-2003 at 09:52 PM.

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    S„o Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use the eval;

    Code:
    function mychange(func)
    { 
       eval(func);
    }
    /Daniel

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Change:

    onChange="mychange(this.options[this.selectedIndex].value)"

    to

    onChange="eval(this.options[this.selectedIndex].value)"

    Not the best way to do this but it should work.

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Saskatoon SK Canada
    Posts
    174
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Excellent.

    ...actually two thumbsup!

    Colin


  •  

    Posting Permissions

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