Change the switch to a non-initial state, not registered

I'm trying to work, I'm sure this is a simple and simple solution, because switch groups are monitored for state changes. Here is one of these groups:

<div class="formRowDiv">
      <label><span>TLan:</span></label>
        <label>
          <input type="radio" id="tlanYes" name="tlan" value="tlanYes"
            <?php
              if ( $inputValArr[ 'tl' ] == "1" ) {
                echo ' checked';
              }   
            ?>
          >
          <span class="radioLabel">Yes</span>
        </label>
        <label>
          <input type="radio" id="tlanNo" name="tlan" value="tlanNo"
            <?php
              if ( $inputValArr[ 'tl' ] == "0" ) {
                echo ' checked';
              }   
            ?>
          >
          <span class="radioLabel">No</span>
        </label>
      <script>
        $(document).ready(function() {
          $("input:radio[name='tlan']:checked").change(function() {
            if ($("input[name='tlan']:checked").val()=='tlanNo') {
              alert( 'tlan: No' );
            } else if ($("input[name='tlan']:checked").val()=='tlanYes') {
              alert( 'tlan: Yes' );
            } // close IF
          }); // close anon FUNC .change
        }); // close anon FUNC doc.ready
      </script>
    </div><!-- close formRowDiv -->

The form has its own input values, initially determined by extracting them from mySql query ().

If the value originally set by the mySql query is 0 and therefore "No" (value = "tlanNo"), then when the user clicks to change the field to "Yes", the warning does not fire, and when I look at the source of the page, this No button that is still checked.

"", "", , , ( ?) "".

, ​​ $_SESSION. , , , , "" ?

BTW: jQuery lib, html.php, :

<script type="text/javascript"  src="jquery-3.2.0.min.js"></script> 
+4
1

: , .

$("input:radio[name='tlan']").change(function() { ...

 $("input:radio[name='tlan']:checked").change(function() { ...
+1

Source: https://habr.com/ru/post/1673301/


All Articles