• Resolved artmobbing

    (@artmobbing)


    Using CF7 for wordpress, I want to populate a textfield using the option selected in a dropdown. The expected result is that when I select a specific value in “oggetto” then the textfield “recipe” is populated with a string. I cannot figure out why this simple jquery script doesnt work on CF7…
    I can make it work on fiddle:
    https://jsfiddle.net/m460t7pu/1/
    The script:

    
            <script text="text/javascript">
            console.log("Inside the script");
            var valore; 
            jQuery('#oggetto').change(function(){
            console.log("I'm inside");
            valore = jQuery('#oggetto').val();
            console.log(valore);
            if (valore == "Corsi") {
            console.log("Now I know what to do");
            //jQuery('#recipe').val("[email protected]");
            document.getElementById("recipe").value = "[email protected]"
            }
            else  {
            jQuery('#recipe').val("[email protected]");
            }
            });
            </script>

    The form, where “id:” defines both the fields’ ids involved:

    <div class="row">
    <div class="col-sm-6">[text* your-name placeholder "Nome e cognome *"]</div>
    <div class="col-sm-6">[email* email placeholder "Email *"]</div>
    <div class="col-sm-6">[tel phone "Telefono"]</div>
    <div class="col-sm-12">[email* destinatario id:recipe]</div>
    <div class="col-sm-6">[select* subject id:oggetto "Oggetto della richiesta *" "Corsi" "Informazioni generali" "Informazioni sugli eventi" "Partnership" "Altro"]</div>
    <div class="col-xs-12">[textarea* message placeholder "Messaggio *"]
    
    [submit class:btn "Invia"]</div><div class="col-xs-12"></div></div>

    I used

    document.getElementById(“recipe”).value
    and

    jQuery(‘#recipe’).val(“[email protected]”);
    just after many many attempt. But every change done inside the function seems useless because by the console.log… code execution seems to stop before the change event. Any idea on what’s wrong in my script?

Viewing 1 replies (of 1 total)
  • Thread Starter artmobbing

    (@artmobbing)

    Ok…
    Just insert the js after the html layout of the form.
    This did the trick for me.
    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘CF7 and Jquery’ is closed to new replies.