coleguitajuan 0 Newbie Poster

Dear Sirs,
I have this code to populate a text field:

<script type="text/javascript"> 
 window.onload=function() {  
  if (document.getElementById("country")) { 
 document.getElementById("country").onchange=function() { switchme(this); }  
  } 
 } 
 function switchme(SNewSel) { 
 var ind = SNewSel.selectedIndex; 
 var txt = document.getElementById('country_code');
 switch (ind) { 
  case 1: txt.value = "+93"; break; 
  case 2: txt.value = "+358"; break; 
  case 3: txt.value = "+355"; break; 
 default: 
 txt.value=''; 
 break; 
 } 
} 
</script> 
<form action="output.php" method="post" name="myform" id="myform">
<input id="country_code" name="country_code" size="4" maxlength="6" class="boxinput">
<select name="country" id="country">
<option value="Choose One" selected="selected" >Choose One</option>
<option value="AFG">Afghanistan</option>
<option value="ALA">Aland Islands</option>
<option value="ALB">Albania</option>

But if I want to delete a country it will move to the upper or down and will not match the proper country code. Any idea?

Thanks,
Cole

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.