bine.heckmann Posted October 26, 2010 Share Posted October 26, 2010 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 Quote Link to comment Share on other sites More sharing options...
bine.heckmann Posted October 27, 2010 Author Share Posted October 27, 2010 I just thought, maybe could this be done with arrays ? I tried some things but without any luck Any help is greatly appreciated ! Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 27, 2010 Share Posted October 27, 2010 Begin by showing us... (1) your form (2) your db table structure (presuming you are using a table to store data) (3) whatever coding you have tried thus far Quote Link to comment Share on other sites More sharing options...
bine.heckmann Posted October 27, 2010 Author Share Posted October 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.