jeudi 20 octobre 2016

hide/show php checkbox by id like http://ift.tt/2eUqinn

I have a form and a checkbox. By click on the checkbox, a div within some other divs will show up or hide. This works! But, if i visit my page with an id like xxxxx.php?id=10, the checkbox is checked but the divs are hide. if i click on the checkbox, the divs will show up, but the checkbox is unchecked (bad for e.g. mysql updates).. hope anyone can help me by this issue..

Here my code:

$(document).ready(function() {
  $('#Show').hide();
  $("input[name=mycheckbox]").click(function () {
    $('#Show').toggle();
  });

});
<script src="http://ift.tt/1oMJErh"></script>

<form id="form">
  <div class="form-group">
    <div class="form-group">
      <div class="checkbox-inline">
        <label>
          <input type="checkbox" name="mycheckbox" id="mycheckbox" value="yes"> my option
        </label>
      </div>
    </div>

  </div>
  <div id="Show">
    <div class="form-group">
      <label for="textinput" class="control-label">Company </label>
      <div class="">
        <input type="text" class="form-control" name="name" id="name" placeholder="" value="">
      </div>
    </div>
  </div>
</form>

My input field have this code (php doesn't work in the snippet):

<input type="checkbox" name="mycheckbox" id="mycheckbox" value="yes" <?php if (isset($_GET['id'])) {echo $row->mycheckbox == "yes" ? 'checked="checked"' : "";}?>

thanks for your help!




Aucun commentaire:

Enregistrer un commentaire