hollydalby
asked on
Passing this.value into php function whilst setting image source
Hi,
I am trying to change an image source when the user selects from a drop down box in a form on a web page, but I cannot get the syntax correct.
The following works fine if I set $eventpic earlier on in the code. but what I really want to do is change $eventpic to this.value, ie the selected value in the combo box. Any ideas would be gratefully received.
<select class='input-box' name='myeventtypeid' onChange='if(this.selected Index!=0){ document.g etElementB yId("theIm age").src= "<?php echo retrieve_pic($eventpic);?> ";}'>
I am trying to change an image source when the user selects from a drop down box in a form on a web page, but I cannot get the syntax correct.
The following works fine if I set $eventpic earlier on in the code. but what I really want to do is change $eventpic to this.value, ie the selected value in the combo box. Any ideas would be gratefully received.
<select class='input-box' name='myeventtypeid' onChange='if(this.selected
That last one will definately not work, but this may be worth a try:
<?php echo retrieve_pic(?>document.ge tElementBy Name(\"mye venttypeid \").value< ?php);?>
You may need to add spaces between the ..( and ?..., and the ...php and )...
<?php echo retrieve_pic(?>document.ge
You may need to add spaces between the ..( and ?..., and the ...php and )...
ASKER
Hi - thanks for helping - I tried this and get the following error:
Parse error: parse error, unexpected ';', expecting ')'
Thanks,
Holly
Parse error: parse error, unexpected ';', expecting ')'
Thanks,
Holly
Try again but put speech marks (") between ( + ? and php + )
ASKER
Hi - new line looks like:
<select class='input-box' name='myeventtypeid' onChange='if(this.selected Index!=0){ document.g etElementB yId("theIm age").src= "<?php echo retrieve_pic("?>document.g etElementB yName(\"my eventtypei d\").value <?php ");?>";}'>
Page is displaying now, but image is not being found..
<select class='input-box' name='myeventtypeid' onChange='if(this.selected
Page is displaying now, but image is not being found..
It may actually be getElementsByName
Try that, or alternatively, assign an ID to the select box and use getElementByID(\"selectbox id\") instead.
Try that, or alternatively, assign an ID to the select box and use getElementByID(\"selectbox
ASKER
Hi - tried both suggestions, code now looks like:
<select class='input-box' name='myeventtypeid' id='myeventtypeid' onChange='if(this.selected Index!=0){ document.g etElementB yId("theIm age").src= "<?php echo retrieve_pic(" ?>document.getElementByID( \"myeventt ypeid\").v alue <?php ");?>";}'>
Still not gettting the image displayed..
Aaah!!
<select class='input-box' name='myeventtypeid' id='myeventtypeid' onChange='if(this.selected
Still not gettting the image displayed..
Aaah!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for all your help so far, I'll have another look at getElementById in the morning. Thanks again, Holly
Not sure if that would work, but worth trying, and I'll look in to it.