Reputation: 577
I created a radio button in which when user click on yes value then text box is shown to user otherwise they remain hide.
My question when user select yes then I am able to store yes value in sql but when user click on no value that value is not stored in datbase
<script>
$(document).ready(function(){
$(function() {
$('input[name="yeshave"]').on('click', function() {
if ($(this).val() == 'yes') {
$('#textboxes').show();
} else {
$('#textboxes').hide();
}
});
});
});
</script>
no radio button code:
<table>
<tr>
<td>Do you haver passport:</td>
<td><input type="radio" name="yeshave" value="yes"> Yes</td>
<td><input type="radio" name="yeshave" value="no"> No</td>
</tr>
</table>
SQL code is:
if(isset($_POST['yeshave']))
{
$selectedValue=$_POST['yeshave'];
}
$query = "INSERT INTO upload (name, size, type, image,passport_no,dateofissue,dateofexpiry,placeofissue, having_passport ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$image','".$passno."','".$doi."','".$doe."','".$poi."','".$selectedValue."')";
mysqli_query($conn,$query) or die('Error, query failed');
Upvotes: 2
Views: 559
Reputation: 87213
JavaScript:
$(document).ready(function() {
$('input[name="yeshave"]').on('click', function() {
$('#textboxes').toggle($(this).val() == 'yes');
});
});
In PHP:
$selectedValue = $_POST['yeshave'] ? $_POST['yeshave'] : 'no';
$(function()
inside ready
toggle
to hide/show #textboxes
no
Upvotes: 2
Reputation: 31749
Set check one of them. Try with -
$selectedValue = isset($_POST['yeshave']) ? $_POST['yeshave'] : 'no';
Upvotes: 2