Getting selected option value without postback/submit PHP
you need to use onchange
event
$('select').on('change', function() {
var value= this.value ;
$.ajax({
url:'action.php',
type:'POST',
data: {
'value':value
},
success: function(data) {
alert(data);
}
});
})
And make file action.php
if(isset($_POST['value'])) {
$username = $_POST['value'];
//your database query
$query=something;
if ($query) {
echo 'success';
}
else {
echo 'something went wrong';
}
}
Get value without submitting it
See this fiddle
You can use Javascript to do this. See the below JS
function addValues() {
var a = 0,
b = 0;
var e = document.getElementById("radio");
a = e.options[e.selectedIndex].value;
var e1 = document.getElementById("radio1");
b = e1.options[e1.selectedIndex].value;
alert(parseFloat(a) + parseFloat(b));
}
Add the above JS inside a <script>
before you close the <body>
.
The function will be invoked by clicking a button. The HTML for button would be as follows
<button onclick="addValues()">Click to add</button>
Update
See the fiddle
Updated HTML
<ul>
<li>
<select name="radio" id="radio">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</li>
<li>
<select name="radio1" id="radio1">
<option value="1.2">1.2</option>
<option value="3.1">3.1</option>
<option value="0.3">0.3</option>
<option value="1.2">1.2</option>
</select>
</li>
</ul>
<button onclick="addValues()">Click to add</button>
<br/> Result=
<span id="result"></span>
Updated JS
function addValues() {
var a = 0,
b = 0;
var e = document.getElementById("radio");
a = e.options[e.selectedIndex].value;
var e1 = document.getElementById("radio1");
b = e1.options[e1.selectedIndex].value;
document.getElementById("result").innerHTML = (parseFloat(a) + parseFloat(b));
}
Update
If you don't want the button, you can just listen for the change
event of the select
.
See this fiddle
How to submit a selected value without a submit button?
You can call function inside the select dropdown.
<select id="sel_id" name="sel_name" onchange="this.form.submit();">
<option value="-1">Select</option>
<option value="6">kasper </option>
<option value="13">adad </option>
<option value="14">3204 </option>
</select>
Related Topics
Sending Message in Telegram Bot With Images
What Is the Default Username and Password of Phpmyadmin
How to Add Dynamic Filter Using PHP MySQL Ajax
How to Store Values from Foreach Loop into an Array
Disable Xampp Redirect Http to Https
How to Update Stock Quantity Using MySQL in PHP
Convert Accented Characters to Their Plain Ascii Equivalents
Get All Hrefs from String But Then Replace Via Another Method
How to Get Useful Error Messages in PHP
MySQLi or Pdo - What Are the Pros and Cons
How to Download an Mp3 File from Remote Url
How to Enable the Mysqli Extension in PHP 7
How to Save a Png Image Server-Side, from a Base64 Data Uri
How to Pass an Array Within a Query String
How to Pass a Number With Forward Slash "/" to Codeigniter Controller Using Ajax
How to Delete Completed Orders in Woocommerce Using a My SQL Query