I deleted my last question from yesterday, and I have read to understand what to ask. So here I go again:
I am trying to get my script to get the correct value from the select, based on which button is clicked.
I have the following small redirecting script:
(function($){
// bind change event to select
$("#button1,#button2").on('click', function () {
var url = $("#form-field-dynamic_select :selected").val();// get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
})(jQuery);
I have this html:
FORM 1:
<select name="form_fields[dynamic_select]" id="form-field-dynamic_select" class="elementor-class">
<option value="https://www.example.com/page1">Example 1</option>
<option value="https://www.example.com/page2">Example 2</option>
</select>
<button type="submit" class="elementor-button" id="button1">
FORM 2:
<select name="form_fields[dynamic_select]" id="form-field-dynamic_select" class="elementor-class">
<option value="https://www.example.com/page3">Example 3</option>
<option value="https://www.example.com/page4">Example 4</option>
</select>
<button type="submit" class="elementor-button" id="button2">
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.
How can I get it so on FORM 2, it also redirects correctly to /page3 and /page4 if those selects are selected by user?
I am brand new to this, so feel free to explain how I need to think :)
EDIT
What I do understand is that my form-field-dynamic_select 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.
If necessary for a modification on the script, I am able to rename the second select ID to something else.