Link to home
Start Free TrialLog in
Avatar of hollydalby
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.selectedIndex!=0){document.getElementById("theImage").src="<?php echo retrieve_pic($eventpic);?>";}'>
Avatar of Phatzer
Phatzer
Flag of United Kingdom of Great Britain and Northern Ireland image

<?php echo retrieve_pic(?>document.getElementByName("myeventtypeid")<?php );?>

Not sure if that would work, but worth trying, and I'll look in to it.
That last one will definately not work, but this may be worth a try:

<?php echo retrieve_pic(?>document.getElementByName(\"myeventtypeid\").value<?php);?>

You may need to add spaces between the ..( and ?..., and the ...php and )...
Avatar of hollydalby
hollydalby

ASKER

Hi - thanks for helping - I tried this and get the following error:

Parse error: parse error, unexpected ';', expecting ')'

Thanks,
Holly
Try again but put speech marks (") between ( + ? and php + )
Hi - new line looks like:
<select class='input-box' name='myeventtypeid' onChange='if(this.selectedIndex!=0){document.getElementById("theImage").src="<?php echo retrieve_pic("?>document.getElementByName(\"myeventtypeid\").value <?php ");?>";}'>

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(\"selectboxid\") instead.
Hi - tried both suggestions, code now looks like:

<select class='input-box' name='myeventtypeid' id='myeventtypeid' onChange='if(this.selectedIndex!=0){document.getElementById("theImage").src="<?php echo retrieve_pic(" ?>document.getElementByID(\"myeventtypeid\").value <?php ");?>";}'>

Still not gettting the image displayed..

Aaah!!
ASKER CERTIFIED SOLUTION
Avatar of Phatzer
Phatzer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for all your help so far, I'll have another look at getElementById in the morning.  Thanks again, Holly