Dear Sirs,

The below script is working fine on IE but notin Mozilla, could anyone help on this to be working on Mozilla as well?

<script type="text/javascript"> 
 window.onload=function() {  
  if (document.getElementById) { 
 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">
<select name="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>
</select>

thanks in advance,
Cole

I forgot to put the text field where the result is pasted:

<input id="country_code" name="country_code" size="4" maxlength="6" class="boxinput">

Try this.

<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>
</select>

That works perfect!

thanks!

(By Mistake)

Hi,

That works fine, however if you want to remove a country, the code list will move and it wont match the proper country, how would you do that?

Thanks in advance,
Daniel

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.