Home › Forums › Quform WordPress › Populate text field depending on dropdown selection
- This topic has 3 replies, 3 voices, and was last updated 6 years, 3 months ago by
oivanr.
- AuthorPosts
- January 18, 2019 at 5:28 pm #28278
oivanr
ParticipantHI,
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 helpJanuary 19, 2019 at 3:33 am #28284Venom
ParticipantHi,
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>
January 22, 2019 at 3:25 pm #28308Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 28, 2019 at 4:27 am #28348oivanr
ParticipantIt works fine.
Thanks a lot - AuthorPosts
- You must be logged in to reply to this topic.