Title: Button with link
Last modified: August 31, 2016

---

# Button with link

 *  Resolved [sdaglas11](https://wordpress.org/support/users/sdaglas11/)
 * (@sdaglas11)
 * [10 years ago](https://wordpress.org/support/topic/button-with-link-1/)
 * hello there,
 * many thanks for your great plugin.
 * I have a form, calculating a number X, depending on some radio buttons and number
   inputs.
 * Now, i want to have a button that will link to 3 different urls, depending on
   the value of that number X.
 * how can i do that?
 * Regards,
    Spyros
 * [https://wordpress.org/plugins/calculated-fields-form/](https://wordpress.org/plugins/calculated-fields-form/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [10 years ago](https://wordpress.org/support/topic/button-with-link-1/#post-7418356)
 * Hi,
 * There are different solutions, so, I’ll explain one of them:
 * 1. Assign a class name to the calculated field, for example: my-field (the class
   names are assigned to the fields through the attribute: “Add Css Layout Keywords”)
 * 2. I will assume you want to redirect the user to the URL: [http://www.demo.com/page_a](http://www.demo.com/page_a)
   if the value of the calculated field is 1, to the URL: [http://www.demo.com/page_b](http://www.demo.com/page_b)
   if the value of the calculated field is 2, and to the URL: [http://www.demo.com/page_c](http://www.demo.com/page_c)
   if it is 3. Insert a “HTML Content” field in the form, and enter as its content
   the piece of code:
 *     ```
       <script>
       function myOnClick(){
       var v = jQuery('.my-field input').val(), url;
       if( v == 1) url = 'http://www.demo.com/page_a';
       if( v == 2) url = 'http://www.demo.com/page_b';
       if( v == 3) url = 'http://www.demo.com/page_c';
   
       if(typeof url != 'undefined') document.location.href=url;
       }
       </script>
       ```
   
 * 3. Finally, enter as the onclick event of the “button” field, a calling to the
   previous function: myOnClick();
 * and that’s all.
    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Button with link’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [url link](https://wordpress.org/support/topic-tag/url-link/)

 * 1 reply
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/button-with-link-1/#post-7418356)
 * Status: resolved