Title: Javascript redirect on mail-sent
Last modified: March 16, 2019

---

# Javascript redirect on mail-sent

 *  [olufemishield](https://wordpress.org/support/users/olufemishield/)
 * (@olufemishield)
 * [7 years ago](https://wordpress.org/support/topic/javascript-redirect-on-mail-sent/)
 * 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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fjavascript-redirect-on-mail-sent%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 years ago](https://wordpress.org/support/topic/javascript-redirect-on-mail-sent/#post-11321096)
 * `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](https://contactform7.com/dom-events/). There is an example code
   in the middle of the page that shows how to use input values based on field names.
 *  Thread Starter [olufemishield](https://wordpress.org/support/users/olufemishield/)
 * (@olufemishield)
 * [7 years ago](https://wordpress.org/support/topic/javascript-redirect-on-mail-sent/#post-11321230)
 * 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](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 years ago](https://wordpress.org/support/topic/javascript-redirect-on-mail-sent/#post-11322382)
 * 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)

The topic ‘Javascript redirect on mail-sent’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)

 * 3 replies
 * 2 participants
 * Last reply from: [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/javascript-redirect-on-mail-sent/#post-11322382)
 * Status: not resolved