Skip to content Skip to sidebar Skip to footer

How To Pass The Value Of A Form Select Input To A Php File Using Ajax Without Submitting It?

I want to pass the value of a form select input from an HTML form to a php file without submitting it. How may I do that? This is my form:

Solution 1:

You're almost there.

Put the id attribute on the select and instead of the option.

$(document).ready(function(){
    $('#userDomicilioProvincia').change(function(){
        $.ajax({
            type: "POST",
            url: "/ubicacion.php",
            data: { provincia: $(this).val() }
        });
    });
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="form-group"><label>Provincia</label><selectid="userDomicilioProvincia"class="form-control"name="userDomicilioProvincia"><option></option><optionvalue="Capital Federal">Capital Federal</option><optionvalue="Gran Buenos Aires">Gran Buenos Aires</option><optionvalue="Buenos Aires">Provincia de Buenos Aires</option></select></div>

Post a Comment for "How To Pass The Value Of A Form Select Input To A Php File Using Ajax Without Submitting It?"