senca99 Posted October 28, 2009 Share Posted October 28, 2009 hey, I made the following (using only listmenu with 1 option just to test): an index.php: <html> <link href="oefening.css" rel="stylesheet" type="text/css"> <body> <div id="wrapper"> <div id="links"> <form action="index.php" method="get"> <p> <label>selecteer hier iets <select name="menu" id="menu"> <option value= "test"> Naam </option> </select> </label> </p> <p> <input type="submit"/> </p> </form> </div> <div id="rechts"> <? include("script.php"); ?> </div> </div> </body> </html> and a php.script: <html> <body> <? echo $_GET['menu']; ?> </body> </html> This works perfect.But now I want to print on screen an image instead of the word test and I've tried on different ways using the img src code inside the form but it never works:s. Anyone know how to make the image appear instead of the word? thx a lot in advance! Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 where do you want the word "test" to be? in the src? maybe: <img src="<?=$_GET['menu']?>.jpg"> Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 the test word appears were it should,in the div "rechts" that is.But now instead of showing "test" I want to display an image when pressing the submit button. Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 okay. so just include the image tag after your echo statement: <? echo $_GET['menu']; ?> <img src="...url here..." alt="..."> I don't see what's the issue... Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 I have to put it in my script.php? I was working in my index.php the whole time :s Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 it depends where you want it to be. There are a few stuff you should correct before you decide where to place it: 1. script.php need not have <html> and <body> tags. The output from script.php will just replace <? include("script.php"); ?>. You don't usually have <html> and <body> tags within a DIV, do you? 2. You should test whether the form has been submitted before trying to print the variable $_GET['menu']: if(isset($_GET['menu'])){ echo $_GET['menu']; } If you want the image to display only when the user submits the form, then place the image tags WITHIN the curly brackets. Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 Indeed the image should only be displayed when the user presses the submit button,then the code should like this? ==> if(isset($_GET['menu'])) { echo $_GET['menu']; <img src="...url here..." alt="...">} and I have to put this in script.php? Because I tried it and I get errors in the div where the image is supposed to be shown. Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 edit: forgot my <? ?> <? if(isset($_GET['menu'])) { echo $_GET['menu']; <img src="...url here..." alt="...">} ?> Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 Yes, that should be in script.php. script.php <? if(isset($_GET['menu'])) { echo $_GET['menu']; echo "<img src=\"someimage.jpg\" alt=\"Some Text\">"; } ?> Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 works like a charm exept that there is always the label posted together with the image.But thats not really an issue. I've been thinking of expanding the code and give the user more options in the menu (multiple pictures to choose from) but I don't know how to get the outcome to be the selected image.I thought about copying the code in script.php and just change the name of the image but then it displays the 2 images because the script refers to the entire form.I don't really have a solution for this one :s Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 use the following if you want to "get the outcome to be the selected image", without the label. <? if(isset($_GET['menu'])) { echo "<img src=\"".$_GET['menu'].".jpg\" alt=\"Some Text\">"; } ?> If you want multiple images, you will have to use a combo box which allows for more than one option to be selected. but that isn't what you started this topic for Quote Link to comment Share on other sites More sharing options...
senca99 Posted October 28, 2009 Author Share Posted October 28, 2009 yeah I know, I wanted to keep it simple in the beginning and was hoping I could expand further...but I was wrong Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 ok, i'll point you in the right direction... your SELECT must have a MULTIPLE attribute: <select name=".." multiple> when you submit the form, the selected options will be in an array. i believe you will be able to find help on handling and looping through an array online. for each iteration, just print out the <img> tag for each option selected. 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.