...

View Full Version : calling a function



dreamingdigital
03-19-2003, 09:49 PM
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?
:thumbsup:

Danne
03-19-2003, 10:04 PM
Use the eval;




function mychange(func)
{
eval(func);
}

Roy Sinclair
03-19-2003, 10:09 PM
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.

dreamingdigital
03-20-2003, 01:39 AM
Excellent. :thumbsup:

...actually two thumbsup!

Colin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum