Reputation: 63
I have four radio button cold,warm,active,all.It display as button.If I click cold button value 'cold' is passed to the query and vice versa.Based on the radio button The query get changed.
I want to show either cold or warm or active mode of records so I use radio button.
HTML
<input type="radio" name="sta_choice" id="o1" value="Cold" onclick="handleClick(this.val);"><span>Cold</span>
<input type="radio" name="sta_choice" id="o2" value="Warm" onclick="handleClick(this.val);"><span>Warm</span>
<input type="radio" name="sta_choice" id="o3" value="Active" onclick="handleClick(this.val);"><span>Active</span>
<input type="radio" name="sta_choice" value="All" checked><span>All</span>
<div class="ref">
</div>
SQL
$sql="select * from client where active=0 and comp_id='$comp' order by c_name asc limit $i,5";
My problem is I want to pass the value of radio button to the query dynamically
and reload the ref div
If I selected cold I shows only cold value.
Upvotes: 0
Views: 2065
Reputation: 530
I would use jQuery for something like this.
Get the value (the only unique "identifier" available in the code you have provided) of the radio option and send that value via AJAX to a script to be included as a parameter in your query. Finally, output the result of the query in your "ref" div
<script>
$(':radio').on("click", function(e) {
e.preventDefault(e);
alert(this.value); // for testing
$.ajax({
type: "POST",
url: "processor.php",
cache: false,
data: { action: this.value },
error: function(msg) {
alert(msg);
},
success: function(text) {
alert(text); // for testing
$(".ref").html("<p>" + text + "</p>");
}
});
});
</script>
PHP:
<?php
echo 'You sent me '.$_POST['action'];
?>
Upvotes: 1
Reputation: 556
use $comp=$_REQUEST['<radio_name>']
i.e. in your case $comp=$_REQUEST['sta_choice'];
and then pass it in your query which will dynamically fetch data as per your requirement but in case of single condition or single value dependency the radio button works fine but if you want to fetch data depending on multiple value then you should use check boxes with array data type and user WHERE IN ()
function in your query or as suitable depending on your requirement.
Hope this will help you in solving your problem
Upvotes: 0