Jump to content

[SOLVED] Select Box


Daney11

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.