check a radio button based on value retrieved from database
$Share = 'Yes';
$Permission = 'Yes';
<label for="Do you provide consent to share images on our official web page">
Do you provide consent to share images on our official web page? :
</label>
<input type="radio" name="share" <?php echo ($Share =='Yes')? 'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="share" <?php echo ($Share =='No')? 'checked':'' ?> value="No">No<br><br>
<label for="If yes, with Identity">If yes, with Identity? :<br><br></label>
<input type="radio" name="permission" <?php echo ($Permission=='Yes')?'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="permission" <?php echo ($Permission=='No')?'checked':'' ?> value="No">No<br><br>
make radio button checked if it has the right database value
You can change your code to below:
public function getstatusradio () {
$sql = "SELECT ticketstatus FROM ticketpractice WHERE id = 6";
$result = $this->connect()->query($sql);
if ($result-> rowCount() > 0) {
while ($row = $result->fetch()){
$newCheck = $row['ticketstatus']=='new' ? 'checked' : '';
$processingCheck = $row['ticketstatus']=='processing' ? 'checked' : '';
echo "<input type='radio' name='status' $newCheck value='new '>new";
echo "<input type='radio' name='status' $processingCheck value='processing'>processing";
}
}
}
but if you want to use php tag inside "", use htmlspecialchars()
$phpCode = '<? if($condtion){ ?>';
echo htmlspecialchars($phpCode);
Laravel set radio button is checked based on database value
1) NO need two name attribute.
2) you can use {{ ($site->is_active=="0")? "checked" : "" }}
to checked based on database value .
<input type="radio" id="option1" name="status" value="0" {{ ($site->is_active=="0")? "checked" : "" }} >OFF</label>
<input type="radio" id="option2" name="status" value="1" {{ ($site->is_active=="1")? "checked" : "" }} >ON</label>
3) for select box do like this
<selec name="xx" >
<option value="1" {{ ($site->select_values=="1")? "selected" : "" }} ></option>
.
.
</select>
Controller :
$site->update([
'name'=>$request['name'],
'copyright'=> $request['copyright'],
'is_active'=>$request['status'], // == 'true' ? 1 : 0
'message'=>$request['message'],
'datatime'=>date('Y-m-d', strtotime($request['datatime'])),
'url'=>$request['url'],
'metadata'=>$request['metadata']
]);
Select which radio button is checked based from database value Django
To set which radio button is selected without using a Django form, you can apply some logic to each radio button which sets the checked
attribute. Note that you should also ensure that the value
attribute is unique for each element:
<th><input type="radio" name="requirements_completed_{{req.pk}}" value="no"{% if not req.completed %} checked{% endif %}> No
<input type="radio" name="requirements_completed_{{req.pk}}" value="yes"{% if req.completed %} checked{% endif %}> Yes</th>
Related Topics
In Java, How to Combine Two Json Arrays of Objects
Using an Empty Keystore Password Used to Be Possible
How to Save a File Downloaded With Httpclient into a Specific Folder
Gson Expected Begin_Array But Was String At Line 1 Column 62
How to Do Name Validation Allowing Alphabet, Spaces and Dot in Android
Check Username and Password in Java Database and Give Wrong Password Message If False
How to Write Unit Test for a Setter Method Which Does Not Have a Getter Method
How to Get File Extension from Content Type
Why Is Git Bash Not Using the Correct Java Path as Defined in the Path Environment Variable
In Activity.Oncreate(), Why Does Intent.Getextras() Sometimes Return Null
Create List of Object from Another Using Java 8 Streams
How to Check If a Java 8 Stream Is Empty
How to Append a Query Parameter to an Existing Url
Cannot Find Element Using Selenium Webdriver
How to Scroll to the Bottom of a Recyclerview? Scrolltoposition Doesn't Work
Java - Reading Text File as an Integer and Split Each Line into Array