Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
radio button change to non-initialy state not being registered

I have been trying to work what I am sure is an easy, straightforward solution to having groups of radio buttons tracked for state changes. Here is one such group:

<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 input values initially determined by retrieving them from mySql query ().

If the value initially set by a mySql query is 0 and so "No" (value="tlanNo"), then when the user clicks to changes the field to "Yes," the alert fails to fire, and when I look at the page's source it is the "no" button that is still checked.

When the "no" button is selected, changing from the previously selected "Yes," then the alert fires, and the page source shows that it is (still?) the "No" button that is checked.

I want to eventually save the button's changed state to the page's $_SESSION array. Why then would the change to the non-initially set button value not be registering, and so firing the alert as well as reflecting the change in the page's source after the change has been made, but a change "back" to the initial state seems to get registered?

BTW: I do have the current jQuery lib located in html.php's dir and referenced in the page's header like so:

<script type="text/javascript"  src="jquery-3.2.0.min.js"></script> 
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The :checked selector works for checkboxes, radio buttons, and options of select elements.

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

instead of

 $("input:radio[name='tlan']:checked").change(function() { ...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda