简体   繁体   中英

Append get variables to url after form submit without new hidden input

I have hidden input value

<input type="hidden" id="as-values-flexmls_connect480723641" class="as-values" value="&amp;MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&amp;City=Astor,">

how to append the value on the URL after I click form submit

so my current URL http://mysite/advanced-search/ then when after click submit on <form method="get"> goes to get all my variables then append that variable

http://mysite/search/?multiple_get=sdasd&amp;MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&amp;City=Astor,

how to do that? i don't need to create new input hidden cause this is just plugin that created this input...

I have already this script that remove empty variables from get and display on the url only that not empty variable only.

function removeEmptyGetVariables()
{
    var myForm = document.getElementById('form-id');
    var allInputs = myForm.getElementsByTagName('input');
    var input, i;

    for(i = 0; input = allInputs[i]; i++) {
        if(input.getAttribute('name') && !input.value) {
            input.setAttribute('name', '');
        }
    }
}

You may append the variables to your endpoints and then submit the form, like it:

Example:

http://js.do/alvaropaco/append-get-variables-to-url-after-form-submit-without-new-hidden-input

You can use document.ready function to automatically update action value,

$(document).ready(function() {
 // Add a hidden value to the form action
var action = $("#my_form").attr("action"),
append = $("input[name=my_input_name]").attr("value");

$("#my_form").attr("action", action + append);
});

Add a name to your hidden input field,

<form action="" name="my_form">
<input name="my_input_name" type="hidden" id="as-values- flexmls_connect480723641" class="as-values" value="&amp;MLSAreaMinor=13%20-%20Beachside%26%2344%3B%20N%20of%20Dunlawton%20%26%20S%20Silver,&amp;City=Astor,">
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM