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 Quote Link to comment 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 ?>"> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 ? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 $key Quote Link to comment 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 ?>"> Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 You are <3. Thankss a lot. 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.