Populate text field depending on dropdown selection

Home Forums Quform WordPress Populate text field depending on dropdown selection

This topic is: resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28278
    oivanr
    Participant

    HI,
    What I am trying to do is to add a country phoce code to a text field depending on the selection that I make in a dropdown field.
    Here is the code that I already included in CSS&JS Custom;
    jQuery(document).ready(function ($) {
    $(‘.quform_5_11’).change(function () {
    if ($(this).val() == ‘Guatemala’) {
    vCodigo=’502′;
    } else {
    vCodigo=’999′;
    }
    });
    $(‘.quform_5_12’).val(vCodigo);
    });
    where 5_11 is the dropdown field and 5_12 is the phone text field, both are included into a group of fields.
    The phone text field are validated alphanumeric
    At this time when I make the choice nothing happen at the phone field.
    I expect that after the dropdown selection appear this three digits in my phone field.
    Thanks for your help

    #28284
    Venom
    Participant

    Hi,

    I think that is due to the variable not available outside the function scope. You might try this.

    <script>
    jQuery(document).ready(function ($) {

    $('.quform-field-5_11').change(function () {
    vCodigo = '';
    if ($(this).val() == 'Guatemala') {
    vCodigo='502';
    } else {
    vCodigo='999';
    }
    $('.quform-field-5_12').val(vCodigo);
    });

    });

    </script>

    #28308
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #28348
    oivanr
    Participant

    It works fine.
    Thanks a lot

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy