how to select button input range with radio button - php

saya ingin membuat button group untuk skala perbandingan metode AHP

change the code to this format
<label class="btn btn-primary">
<input type="radio" name="skala" id="1" checked>1
</label>
change input checked="checked" to input checked="true" or input checked
the checked property's default value is true

Related

How to populate a radio button group with mysql data?

I need to populate a radio group with the data saved on a mysql database using that very same radio group in a previous session. Now, normally I would just fetch the data into a variable .row and echo it under the value attribute but since the value att. for each radio button is set to the data I need to save if the button is selected I can't use it to show the fetched data form mysql.
How can I show the value previously saved on the database for the radio button group?
I've been looking for different solutions and everybody seems to answer that I should just fetch the date and echo it. Which confuses me because the value attribute is being used to depict what should be saved if the user select the button.
Let's use one of my groups. This question gets saved correctly on submit but I dont know how to show the saved value on refresh.
<div class="one">
<h1 class="text">Qual a cor dos seus olhos?</h1>
</div>
<p>
<label>
<input type="radio" class="option" name="ojos[]" value="Avelã" id="ojos_0">
Avelã</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Castanho oscuro" id="ojos_1">
Castanho oscuro</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Azul" id="ojos_2">
Azul</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Azul esverdeado" id="ojos_3">
Azul esverdado</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Verde" id="ojos_4">
Verde</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Ambar" id="ojos_5">
Ambar</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Cinza" id="ojos_6">
Cinza</label>
<br>
<label>
<input type="radio" class="option" name="ojos[]" value="Violeta" id="ojos_7">
Violeta</label>
<br>
</p>
as I told before, the entire form (which is close to 23 questions like the one posted before) saves perfectly fine. I just need to populate it with the previously saved data.
add a validation to the input with the value you are receiving from your database.
<label>
<input
type="radio"
class="option"
name="ojos[]"
value="Azul"
id="ojos_2"
<?php $ojosval == 'Azul'? echo 'checked' : '' ?>
/>Azul</label>
What I'm doing here is checking if the value you got from the database $ojosval is equal to the value of that input, if the validation is true, you will just add the checked property which will select the radio.
I haven't coded PHP for a while, but I think that should work.

change value of a radio button based on database value in php

i have a radio button in my form
<input type="radio" id="radio-2" name="radio" checked onclick="calculate()" >
how to set the radio button value based on database value like
if(db_val==2){
value=50
} else{
value=100
}
Radio button value is depend on checked attribute
If you set the checked attribute with condition then its value will be set
Example:
<input type="radio" id="radio-2" name="radio" value="50" <?php echo ($db_val==2)?'checked':'' ?> onclick="calculate()" >
<input type="radio" id="radio-2" name="radio" value="100" <?php echo ($db_val!=2)?'checked':'' ?> onclick="calculate()" >

Pre-selected Bootstrap radio buttons won't submit

I have an html file containing a form that is being loaded via php. In this form, all input fields show pre-selected values based on previously entered values. When I submit this loaded form, all the textboxes and text inputs are successfully submitted ; however, the radio buttons ( which also have pre-selected values) are not submitted unless, you click on the selected values again. Is there any way I can fix this?
Here's my simplified html that's being loaded:
<form action="report" method="POST" target="_blank">
<div class="btn-group-xs" data-toggle="buttons" id="rop1-1-cons">
<label class="btn btn-outline-primary active">
<input type="radio" name="rop1-1-cons" id="rop1-1-cons-5" value="5" autocomplete="off">I
</label>
</div>
<input type="text" value="Pre-selected User Input"/>
<input type="submit" value="submit"></input>
</form>
The label has "Active" class which means the user have chosen this before the form html was saved.
I think it's useful to mention that I am using bootstrap style radio buttons (I know, they have strange behaviors!)
Add the checked attribute to the input.
<div class="btn-group-xs" data-toggle="buttons" id="rop1-1-cons">
<label class="btn btn-outline-primary active">
<input type="radio" name="rop1-1-cons" id="rop1-1-cons-5" value="5" autocomplete="off" checked="checked">I
</label>
</div>

How to get value of Bootstrap Toggle Buttons in PHP

I've used multiple Bootstrap Toggle Buttons for some options selection. On submitting form, I want to check which options are selected so that I can save the corresponding values in database using PHP.
Below is how my HTML looks like (inside form) -
<li>
<button type="checkbox" class="btn skillNameBtn" data-toggle="button" aria-pressed="false" autocomplete="off">
Option1 </button>
<button type="checkbox" class="btn skillNameBtn" data-toggle="button" aria-pressed="false" autocomplete="off">
Option2 </button>
<button type="checkbox" class="btn skillNameBtn" data-toggle="button" aria-pressed="false" autocomplete="off">
Option3 </button>
</li>
My question is how do I get value of which options are selected in PHP script? E.g if its simple input field, I use $_POST[]. But in this case what is the way to do the same.
Thank you in advance for help.
You can input a hidden field eg:
<input type="hidden" name="option" value="" id="option">
And use a jQuery:
$('.skillNameBtn').click(function(){
$('#option').val($(this).val());
});
You might add value="Option 1" etc into your buttons for easier work

How to associate Radio Button value with Input Field

I am creating a quiz application...
I have created a question text area, and a number of input fields for options..
Each input field has a radio button, if user clicks it, it will consider the associated input field as correct answer..
I have created some input fields and radio button with each input field
<div id="items">
<input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct" value="yes"/> <br><br>
<input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct" value="yes"/>
</div>
when i Submit this form it stores yes with each Option. I am unable to understand how to store the value of only 1 input field.
Kindly guide me
Thanks.
if you get value of options is input1 answer is input1 or if options value is input2 answer is input2
<input type="radio" name="options" value="input1">Is Correct<br>
<input type="radio" name="options" value="input2">Is Correct
input1 is name of textbox 1
input2 is name of textbox 2
Get value on form post :-
$nam=$_POST['options'];
$answer=$_POST[$nam];
You can use input as below :
<div id="items">
<input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct[]" value="yes"/> <br><br>
<input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct[]" value="yes"/>
</div>

Categories