View Full Version : Change value displayed depending on select list

12-08-2006, 02:02 PM
hi Peeps I'm new to this board :),
I am putting together a form which validates with javascript before submission. I am having a problem at the moment with it. The form asks for a mobile phone number and has a drop down list of country's to select from. When the user selects a country (from the select list), the international dialling code is added onto the front of the number they submit in another field. this bit works fine. What I also want to do is display the dialling code for the country the user selects in another field (just display it). This is the following code I have but it isn't working, nothing at all is displaying within the field when I select a country from the list.

function changeintCode(newintCode){ //change value of int code

var theform;
theform.intCode.value = newintCode;


//select list within the body
<select id="country" name="country" onchange="changeintCode(this.options[this.selectedIndex].value)">
<option value="Country...">Country...</option>
<option value="44">United Kingdom</option>
<option value="93">Afghanistan</option>
//and so on

//Field I want to display the dialling code in

<td>International Dialling Code (ie.44):</td>
<td><input type="text" name="intCode" id="intCode" size="2" maxlength="2" readonly/></td>

Hope somebody can help.
Thanks for reading!