Jump to content

Showing a Picture based on dropdown form after submit


bine.heckmann

Recommended Posts

Hello there,

 

I'm trying to show a picture based on the value that was chosen in the dropdown menu of the page before the submit.

 

Let's say i'm having a drop down form with 3 values: Porsche, BMW, Audi, the form also consists of a button to submit form and some other text fields but these aren't really relevant.

 

So what i want is, you choose whatever car, let's say BMW, fill in all the other data of the form, hit submit, and on the next page it should show a Picture which i define for each car.

 

I hope i explained that somehow understandable.

 

Thanks in advance,

 

Sabine

Ok then, my form:

 

 <select name="fahrzeug" class="dropdownform" id="fahrzeug">
<option value="Audi" selected>Audi</option>
<option value="BMW">BMW</option>
          <option value="Porsche">Porsche</option>
          </select>

 

I'm not using any Database.

 

I'm thinking about something like this:

 

<?php
$picture= array("BMW"=>"pictureurl", "Porsche"=>"pictureurl", "Audi"=>"pictureurl");
$fahrzeug = $_POST['fahrzeug'];
echo $picture[$fahrzeug];
?>

 

Would that work ? And how would i have to put the pictureurl in that code, sorry i'm quite a noobie.

Yes, that would work. I just expanded your code a little bit so you can get a better idea of what to do. You were headed in the right direction, though.

 

<?php
$photos = array('Audi' => 'Audi_picture.jpg', 'BMW' => 'BMW_picture.jpg', 'Porsche' => 'Porsche_picture.jpg');
if( isset($_POST['fahrzeug']) ) {
$display = $photos[$_POST['fahrzeug']];
}
echo "File name: $display<br>";
?>

<img src="path/to/your/images/<?php echo $display; ?>">

<form action="" method="POST">
<select name="fahrzeug" class="dropdownform" id="fahrzeug">
<option value="Audi" selected>Audi</option>
<option value="BMW">BMW</option>
<option value="Porsche">Porsche</option>
</select>
<br>
<input type="submit" value="submit" name="submit">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.