title: JQuery - Get the correct SELECTED-value by click of button when two buttons are in two separate forms using ONE function
body: <p>I deleted my last question from yesterday, and I have read to understand what to ask. So here I go again:</p>
  <p>I am trying to get my script to get the correct value from the select, based on which button is clicked.</p>
  <p>I have the following small redirecting script:</p>
  <pre><code>  (function($){
        // bind change event to select
        $(&quot;#button1,#button2&quot;).on('click', function () {
            var url =  $(&quot;#form-field-dynamic_select :selected&quot;).val();// get selected value
            if (url) { // require a URL
                window.location = url; // redirect
            }
            return false;
        });
    })(jQuery);
  </code></pre>
  <p>I have this html:</p>
  <p>FORM 1:</p>
  <pre><code>&lt;select name=&quot;form_fields[dynamic_select]&quot; id=&quot;form-field-dynamic_select&quot; class=&quot;elementor-class&quot;&gt;
  &lt;option value=&quot;https://www.example.com/page1&quot;&gt;Example 1&lt;/option&gt;
  &lt;option value=&quot;https://www.example.com/page2&quot;&gt;Example 2&lt;/option&gt;
  &lt;/select&gt;
  &lt;button type=&quot;submit&quot; class=&quot;elementor-button&quot; id=&quot;button1&quot;&gt;
  </code></pre>
  <p>FORM 2:</p>
  <pre><code>&lt;select name=&quot;form_fields[dynamic_select]&quot; id=&quot;form-field-dynamic_select&quot; class=&quot;elementor-class&quot;&gt;
  &lt;option value=&quot;https://www.example.com/page3&quot;&gt;Example 3&lt;/option&gt;
  &lt;option value=&quot;https://www.example.com/page4&quot;&gt;Example 4&lt;/option&gt;
  &lt;/select&gt;
  &lt;button type=&quot;submit&quot; class=&quot;elementor-button&quot; id=&quot;button2&quot;&gt;
  </code></pre>
  <p>The way this works as of now, is that in FORM 1 - it works like it should, but in FORM 2 - it redirects to /page2 on both selects.</p>
  <p>How can I get it so on FORM 2, it also redirects correctly to /page3 and /page4 if those selects are selected by user?</p>
  <p>I am brand new to this, so feel free to explain how I need to think :)</p>
  <p><strong>EDIT</strong></p>
  <p>What I do understand is that my <em>form-field-dynamic_select</em> should be unique for each form, and so it should be different in the var URL, and I have played around with getElementByID(), but I just could not get that right.</p>
  <p>If necessary for a modification on the script, I am able to rename the second select ID to something else.</p>