How to post a select result without a submit button using Jquery or Javascript?

BR
BR used Ask the Experts™
on
Dear Experts,
How can I post below select options results to action page without a submit button?
I'm using PHP.

I think I should use JQeuery to that but I don't know how to that?
Could you please help me?

<form name="form1" method="post" action="actionpage.php">
  
<select class="form-control" name="bolge" style="max-width:350px;">
    <option value="">Select?</option>
	<option value="1">1</option>
     <option value="2">2</option>
</select>

</form>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can use ajax:
https://api.jquery.com/jQuery.ajax/
Some example can be like this code:
var values = 'your posted data";
$.ajax({
        url: "Yourtest.php",
        type: "post",
        data: values ,
        success: function (response) {
           // you will get response from your php page 

        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }
    });

Open in new window

Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
jQuery will make this a breeze. Basically, you would hook in to an event (such as when the <select> changes) and then make an AJAX request to the server, passing in the value of the <select>. Something like this:

$('[name=bolge]').change(function() {

    $.ajax({ 
        url : 'actionpage.php',
        method : 'post',
        data : { bolge : $(this).val() },
    })
    .done( function(response) {
        alert( response );
    });

});

Open in new window

This code would POST the value of your selected option to the actionpage.php script ($_POST['bolge']), and then alert whatever your script returned. There are a lot of other options for AJAX calls, and you can read the docs here -> http://api.jquery.com/jquery.ajax/
BRDigital Marketing

Author

Commented:
thank you both

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial