Is this possible? country calling codes in phonenumber depending on chosen country

mostlyseven

Member
Dear All,

I have seen a form where, depending on the chosen country automatically the right country calling code was taken over in the phone number field.

Eg. chosen country "Netherlands". Tel.: +31 (after that the rest of the number could be added)

I have a country drop down list - I could put as value the calling code

I have a phonenumber field

1) How do I tell the phone number field to take over the value of the country the moment this is chosen?
2) How do I tell the phone number field to start typing after the country code?

Is this even possible?
I think this is a really cool feature in a form, so I hope it can be done.
Thank you very much for your help.

Mostlyseven
 
Hi,

You need to check on cascadingdropdown and databasejoin to achieve what you need

Regards

Manos
 
Hi Manos,
I found a Javascript for how to get element value from a dropdown list. I put this under Javascript in the phone element.
The country full element name is: anfrage___land

Code:
var selected_index = oForm.elements['anfrage__land'].selectedIndex;
 
if(selected_index > 0)
{
   var selected_option_value = oForm.elements['anfrage__land'].options[selected_index].value;
   var selected_option_text = oForm.elements['anfrage__land'].options[selected_index].text;
}
else
{
   alert('Bitte w?hlen Sie ein Land.');
}
the action is click on the phone field.

But it doesnt work.
Any Ideas?
 
Hi,

I think the best way is to create a db with elements containing the actual data ( for instance, country, phone number ext, etc) and then a new form with databasejoin and use of cascadingdropdown elements to get that data based on the users selection.

Then using the fabrik's build in functions you can create what you need.


Regards

Manos
 
Using a CDD wouldn't really help, as that wouldn't let him insert it into the start of a field.

I think you are on the right track with that Javascript, but as-is, it isn't actually doing anything with those values.

So try something like this. You'll need to know your numeric form ID, which is the number on the left most column in your main list of Forms on the back end. So in the folowing, replace _X with your ID, like form_123. Also, replace the full element names as appropriate.

Create a 'change' JS event on your country dropdown, with this as the code:

Code:
form_X.formElements.get('yourtable___phone_number').update(form_X.formElements.get('yourtable___country').getValue());
Note that this will replace whatever is in the phone number field, so if they fill out the phone number, then change the country, they'll have to refill the number.

The code could be modified so if the phone number field already contained a value, we could replace an existing country code with the newly selected one.

But just to get started, try the above code, see if it works.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top