Jump to content

international calling code


Sibkis

Recommended Posts

HelloI have been seaching the forum for the answer but can't find it.I have a form with a country dropdown and each country has it's country code attached to it.the phone section has 3 part the country code areacode and local. +xx xxxx xxxxxxhow can I get the country code to be filled depending on the country selected.can someone please point me in the right direction <label for="country">Country:</label> <select name="country" id="country" class="selectOne"> <option value="<?php print "$country"; ?>"Select a Country /> <option value="CN" countrynum="86">China (Mainland)</option> <option value="CA" countrynum="1">Canada</option> <option value="HK" countrynum="852">Hong Kong</option> <option value="IN" countrynum="91">India</option>Thanks

Link to comment
Share on other sites

You will need to use javascript. you can bound a function on onchange event on that dropdown. hat function will get the input of dropdown and access the node where the phone number resides and will get its value. then you can append the first two digits of value from the dropdown, to it.

Link to comment
Share on other sites

Hi BirbalSo use something like <select name="country[0]" onChange="checkCountryField(this.value)" ><option value="<?php print "$country"; ?>"Select a Country /><option value="CN" countrynum="86">China (Mainland)</option><option value="CA" countrynum="1">Canada</option><option value="HK" countrynum="852">Hong Kong</option><option value="IN" countrynum="91">India</option>I think.Iam not to good with javascript.

Link to comment
Share on other sites

yes something like that. hope you have the checkcountryFiled() defined to get done the rest of the job.

Link to comment
Share on other sites

umm nodo you know of a good place to find out what I need to do.but I think something like this<script type="text/javascript">function checkcountryField(){ var sel = document.getElementById("checkcountryField"); location = sel.options[sel.selectedIndex].value;}</script>then with <input id="phone" type= "text" name="int" style="width:40px;" maxlength="8" value="" onchange="checkcountryField()" /> as the destination

Link to comment
Share on other sites

Try this and see if it tells you the correct code:

function checkcountryField(){  var sel = document.getElementById("checkcountryField");  var code = sel.options[sel.selectedIndex].getAttribute('countrynum');  alert(code);}

Link to comment
Share on other sites

Here is a test code I have been attempting to win the battle with.

<script language="JavaScript"><!--function onChange() {var Current =document.formName3.selectName3.selectedIndex;document.formName3.currentText3.value =document.formName3.selectName3.options[Current].text;document.formName3.currentValue3.value =document.formName3.selectName3.options[Current].value;}//--></script><form name ="formName3" onSubmit="return false;"><select name = "selectName3" onChange="onChange()"><option value = "Option 0"><option value = "CN" countrynum ="86">China (Mainland)</option><option value = "CA" countrynum ="1">Canada</option><option value = "HK" countrynum ="852">Hong Kong</option>Entry 0<option value="Option 1">Entry 1</select><input name="resetName3" type="reset" value="Clear"><br><br>Current Text:<input name="currentText3" type="text" value="">Current Value:<input name="currentValue3" type="text" value=""></form>

Link to comment
Share on other sites

Hi justsomeguyI could not get it to work but the code below works very well<script language="JavaScript"><!--function onChange() {var Current =document.regform.Country.selectedIndex;document.regform.Country.value =document.regform.Country.options[Current].text;document.regform.countrycode.value =document.regform.Country.options[Current].id;}//--></script><form id="form" method="post" action="" name ="regform" onSubmit="return false;" ><label for="country">Country:</label><select name = "Country" onChange="onChange()"> <option value="" /><option value = "CN" id = "86">China (Mainland)</option><option value = "CA" id ="1">Canada</option><option value = "HK" id ="852">Hong Kong</option></select><input name="resetName3" type="reset" value="Clear"><br><br>Country Code:<input name="countrycode" type="text" value=""></form>Thanks for the help

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...