简体   繁体   中英

Contact Form 7 - populate textfield based on Select input

Sorry if this has been answered before, but I cannot find a solution. I am developing a form in Contact Form 7 for wordpress.

I have a select box

<label> poems
[select choosePoem "-- Velg fra listen" "Ditt hjerte som banket..." "Høyt 
elsket..." "Skjønt å få hvile..." "Hjertet som banket for andre..." "Stille kom døden..." "Stå ikke ved..."]</label>

and a textarea

[textarea poem_1_1]

Now, I want to populate the textarea with the selected poem which is chosen using the selectbox.

I was thinking of using a Json Object or array as the poem storage. But I am at loss as how to make this work in the function section of Contact Form 7.

I have looked into the plugins "Dynamic Text Extension" and "Conditional field". But only thing I could make work ended up using several textarea-boxes. which is in my book a whole lot of wasted code. I have read that I should be able to use jQuery for this, but I am at loss as to how it works.

I was thinking something like this:

(function($) {
   $('choosePoem').on('change', function() {
      switch ($(this).value(//Something//)) {
        case 'no':
         //something here
        break;
}

   }
}

Any ideas, suggestions, links to working examples, would very much be appreciated. Thank you.

Please change your jquery and try it

(function($) {
    jQuery('textarea[name="poem_1_1"]').hide();
    jQuery('select[name="choosePoem"]').on('change', function() {   
        switch (jQuery(this).val()) {
            case 'Ditt hjerte som banket...':
             jQuery('textarea[name="poem_1_1"]').show();
            break;
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM