0

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

asked Oct 26, 2011 at 23:00
1
  • 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. Commented Oct 26, 2011 at 23:06

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.