Support » Plugin: Contact Form 7 » Javascript redirect on mail-sent

  • olufemishield

    (@olufemishield)


    Hello All,

    I have the following code to redirect users to different pages depending on the radio button selected on a form on my home page but it isn’t working. Could anyone point me to what I didn’t do right?

    Thank you
    ———————————————

    <script type=”text/javascript”>
    document.addEventListener( ‘wpcf7mailsent’, function( event ) {

    if ( ‘13130’ == event.detail.contactFormId ) {

    var AcquisitionType = document.getElementById(“mc4wp-ACQTYPE”).value;

    if (AcquisitionType == “Buying”) {
    location = ‘https://afrihood.com/payment/engagement/buying-request/’;
    } else if (AcquisitionType == “Renting”) {
    location = ‘https://afrihood.com/payment/engagement/rental-request/’;
    }else if (AcquisitionType == “Short-let”) {
    location = ‘https://afrihood.com/payment/engagement/short-let-request/’;
    }

    }
    }, false )
    </script>

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    var AcquisitionType = document.getElementById("mc4wp-ACQTYPE").value;

    This won’t work because “mc4wp-ACQTYPE” is not the id attribute value but the name attribute value of the input elements.

    See DOM Events. There is an example code in the middle of the page that shows how to use input values based on field names.

    olufemishield

    (@olufemishield)

    Thank you Takayuki. I used the id attribute “acquisition-type” as set in my form but it still didn’t redirect. I would appreciate further hints.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    The id “acquisition-type” is given to the wrapper span element, not to the radio button input element, therefore document.getElementById("acquisition-type").value is always empty.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.