1

I have developed a site for a client that uses a profile to capture address and contact information for event registrations using CiviEvent. One of the fields on the registration form is a 'Country' field. There is a requirement from the client to fill in another form field with a default value based upon the Country selected. I have done similar things with jQuery in relation to other fields on the form, but the country field widget is quite complicated and I can't quite figure out how to target the user's selecting a country and get the country value with jQuery. I am sure there must be some code in CiviCRM that does this, in order to display the correct set of state/province fields based upon the country selection. But I have not been able to locate such code. Can anyone give me any pointers in terms of where I can find the CiviCRM code that does this, or sample JS/jQuery code that will detect the country field selection on a profile form? Note that this is on CiviCRM 4.6.2.

Many thanks, -Ian

  • it is not working when select element is hidden – Elena Kaminsky Mar 21 '16 at 12:48
  • Hi @ElenaKaminsky: StackExchange uses a Question and Answer format, rather than a forum thread format. Please feel free to post a new question explaining your issue, with a link to other questions like this one if they provide some context. When you post your question, try to include more information about what you are trying to achieve, how you are going about that, what is not working (especially error text), and what you have tried so far to solve the problem. – Joe Murray Mar 21 '16 at 15:46
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review – petednz - fuzion Mar 21 '16 at 18:55
2

The select2 is indeed complicated but you don't need to go there. The underlying select element is still there (just hidden) and still fires regular "change" events and you can still get it's value using the ordinary $(element).val() jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.