[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1208
  • Last Modified:

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);?>";}'>
0
hollydalby
Asked:
hollydalby
  • 5
  • 4
1 Solution
 
PhatzerCommented:
<?php echo retrieve_pic(?>document.getElementByName("myeventtypeid")<?php );?>

Not sure if that would work, but worth trying, and I'll look in to it.
0
 
PhatzerCommented:
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 )...
0
 
hollydalbyAuthor Commented:
Hi - thanks for helping - I tried this and get the following error:

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

Thanks,
Holly
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PhatzerCommented:
Try again but put speech marks (") between ( + ? and php + )
0
 
hollydalbyAuthor Commented:
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..
0
 
PhatzerCommented:
It may actually be getElementsByName

Try that, or alternatively, assign an ID to the select box and use getElementByID(\"selectboxid\") instead.
0
 
hollydalbyAuthor Commented:
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!!
0
 
PhatzerCommented:
Not sure if theres much else I can suggest off the top of my head. Unfortunately I'm not going to be available until tomorrow now. I hope somebody else helps you further.
0
 
hollydalbyAuthor Commented:
Thank you for all your help so far, I'll have another look at getElementById in the morning.  Thanks again, Holly
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now