I have a Javascript function that I need to modify to accept arguments, one for the image id and the other for the select box's id.
<script type="text/javascript">
function swapImage(){
var image = document.getElementById("imageToSwap");
var dropd = document.getElementById("dd");
image.src = dropd.value;
};
</script>
So I'd like to be able to do something like
onChange="swapImage('this','<?php echo $image; ?>')"
I've tried changing it to
<script type="text/javascript">
function swapImage(pic,selectbox){
var image = document.getElementById(pic);
var dropd = document.getElementById(selectbox);
image.src = dropd.value;
};
</script>
But this doesn't work. Please help. Thanks
-
If you say that this doesn't work, then prepare for questions like what do you mean?. Anyway, alex's answer seems to point you to the right direction.Tadeck– Tadeck2011年10月26日 23:06:08 +00:00Commented Oct 26, 2011 at 23:06
1 Answer 1
If you make the 'this' into this, you can then reference it as any other element (skip the getElementById() stuff).
answered Oct 26, 2011 at 23:02
alex
492k205 gold badges891 silver badges992 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js