Title: Passing JavaScript variables
Last modified: August 21, 2016

---

# Passing JavaScript variables

 *  Resolved [himynameisvan](https://wordpress.org/support/users/himynameisvan/)
 * (@himynameisvan)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/passing-javascript-variables/)
 * I need to pass the value submitted for the person’s email address, though to 
   the thank you (e.g. redirect page) upon successful submission. I have to use 
   JS for this – any tips?
 * [http://wordpress.org/plugins/mailchimp-for-wp/](http://wordpress.org/plugins/mailchimp-for-wp/)

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

 *  Plugin Author [Danny van Kooten](https://wordpress.org/support/users/dvankooten/)
 * (@dvankooten)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/passing-javascript-variables/#post-4443766)
 * Hi there,
 * So, you have a redirect URL set in the plugin settings and you want to use the
   provided email address on the URL being redirected to?
 * I would use one of the plugin hooks, write your own redirect function and then
   read from the hash.
 * **PHP (eg in your theme its functions.php)**
 *     ```
       function my_prefix_redirect_with_email($email, $merge_vars, $form_id, $result) {
       	if($result == true) {
       		wp_redirect("/thank-you/#{$email}");
       		exit;
       	}
       }
   
       add_action('mc4wp_after_subscribe', 'my_prefix_redirect_with_email', 10, 4);
       ```
   
 * **JavaScript on thank you page**
 *     ```
       <script>
       var email = window.location.hash.substring(1);
       </script>
       ```
   
 * Hope that helps!
 * Another option would be to set a cookie using the same hook as in my example.
   Or, use a session variable and print it into a JavaScript variable. Just some
   thoughts, this should get you going. 🙂
 *  Thread Starter [himynameisvan](https://wordpress.org/support/users/himynameisvan/)
 * (@himynameisvan)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/passing-javascript-variables/#post-4443928)
 * Thanks so much – I will give this a shot.
 * Am a bit of a hook newbie though – I’ve added the new function and JS to the 
   thank you page, but do I need to do anything with the plugin’s files?
 *  Plugin Author [Danny van Kooten](https://wordpress.org/support/users/dvankooten/)
 * (@dvankooten)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/passing-javascript-variables/#post-4443940)
 * Nope, that’s wat hooks and filters are for – customizing the way a plugin works
   without having to mess with the plugin files itself. 🙂
 * You can add the hooks to your theme its `functions.php` file, for example. That
   way, you can safely update the plugin to benefit from new features and bug fixes.
 * Hope that helps!

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

The topic ‘Passing JavaScript variables’ is closed to new replies.

 * ![](https://ps.w.org/mailchimp-for-wp/assets/icon-256x256.png?rev=1224577)
 * [MC4WP: Mailchimp for WordPress](https://wordpress.org/plugins/mailchimp-for-wp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailchimp-for-wp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailchimp-for-wp/)
 * [Active Topics](https://wordpress.org/support/plugin/mailchimp-for-wp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailchimp-for-wp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailchimp-for-wp/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Danny van Kooten](https://wordpress.org/support/users/dvankooten/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/passing-javascript-variables/#post-4443940)
 * Status: resolved