Daney11 Posted December 13, 2007 Share Posted December 13, 2007 Hey guys, Im using <?php echo '<select name="member_nation">'; echo '<option value="NoNation" selected="selected">Please Select...</option>'; foreach ($location as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; ?> and it works perfect. Now im not at all sure how to make it so when they select a $value, the image comes up at the side <?php echo '<select name="member_nation">'; echo '<option value="NoNation" selected="selected">Please Select...</option>'; foreach ($location as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; ?> <img src="flags/<?php echo $member_nation ?>"> So that everytime a value is selected the image changes with it.... Anyone know how to do this? Thanks Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/ Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 well that will be done by javascript you'll have to use the onchange event of a select box try this not sure it will work as I have not tested it <?php echo "<select name=\"member_nation\" onChange=\"document.getElementById('flag').src = this[this.selectedIndex].value\">"; echo '<option value="NoNation" selected="selected">Please Select...</option>'; foreach ($location as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; ?> <img id='flag' src="flags/<?php echo $member_nation ?>"> Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413660 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 Nope, that doesnt work mate. However i refreshes when selected. Actually it does work. but doesnt do the extention .gif even though its there Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413666 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 Even if i add .gif at the end it doesnt work. and it gives me http://localhost/ai not /flags and .gif Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413668 Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 Is it the $key or the $value which is the gif image ? Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413672 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 $key Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413676 Share on other sites More sharing options...
rajivgonsalves Posted December 13, 2007 Share Posted December 13, 2007 I see try this code <?php echo "<select name=\"member_nation\" onChange=\"document.getElementById('flag').src = 'flags/'+this[this.selectedIndex].value+'.gif';\">"; echo '<option value="NoNation" selected="selected">Please Select...</option>'; foreach ($location as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; ?> <img id='flag' src="flags/<?php echo $member_nation ?>"> Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413682 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 You are <3. Thankss a lot. Link to comment https://forums.phpfreaks.com/topic/81480-solved-select-box/#findComment-413683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.