2015-05-29 05:56


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

  $(function() {
     $('input[name="yeshave"]').on('click', function() {
        if ($(this).val() == 'yes') {
        } else {

no radio button code:

      <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>

SQL code is:


 $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');
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douxunwei8259 douxunwei8259 6年前

    Set check one of them. Try with -

    $selectedValue = isset($_POST['yeshave']) ? $_POST['yeshave'] : 'no';
    点赞 评论 复制链接分享
  • duanru6816 duanru6816 6年前


    $(document).ready(function() {
        $('input[name="yeshave"]').on('click', function() {
            $('#textboxes').toggle($(this).val() == 'yes');

    In PHP:

    $selectedValue = $_POST['yeshave'] ? $_POST['yeshave'] : 'no';
    1. You don't need $(function() inside ready
    2. Use toggle to hide/show #textboxes
    3. In PHP, check if value is present, if not use default no
    点赞 评论 复制链接分享