Reputation: 1301
I need to submit combo box value with out form. When I click on any value of combo that suppose to submit automatically using javascript. I am using PHP in backend.
<select name="select" id="select" style="width:50px;">
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="All">All</option>
</select>
Upvotes: 0
Views: 2343
Reputation: 3532
Here a js part:
function getinfo() {
var aList = document.getElementById("select");
var val = aList.options[aList.selectedIndex].value;
// document.write("<p>Here what you select: "+val+"</p>");
// here you can send `val` to the server using... are you using any js library?
}
And you need to change your select
declaration:
<select name="select" id="select" style="width:50px;" onchange="getinfo()">
--------------------
</select>
OK, how to send val
to the server is another question... If you are using jQuery - you can use jQuery.ajax(...)
or any helper like jQuery.get(...)
. If you are vanilla-js user you can use XMLHttpRequest
way and if you use any other lib - just check this lib's documentation to get helped about sending data to the server.
Upvotes: 2
Reputation: 1533
You can use the methods below.
1) Use Session or Cookie to send external data
2) Send a POST request using XMLHttpRequest in javascript.Checkout the link here.
3)You can use cURL function to send HTTP POST request. Please go through the link here.
Upvotes: 1
Reputation: 49104
Some comments:
The select
element should always be inside a form.
But you don't need to expose the form on the page--you do not need to include a submit
input element.
You can use Javascript (JS) to submit the form after the user has changed the value of the select.
Or you can use JS with Ajax to submit the form asynchronously in the background--the user will not be aware that the data had been submitted and the page will not reload or "flash"
What would you like to do?
Upvotes: 0