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

226
Vistas
Using variables in PHP input radio name tag and get value on JQUERY or JAVASCRIPT

I have a PHP file that creates radio buttons based on pets ids. The var $idperro is a number that changes dynamically to identify the set of radio buttons independently. I am trying to put the value inside the p tag.

Heres the PHP

<?php

echo '
    Jack Baño: <input type="radio" name="'.$idperro.'/servicio" value="'.$idperro.'/baño/'.$baño.'">
    Jack Corte: <input type="radio" name="'.$idperro.'/servicio" value="'.$idperro.'/corte/'.$corte.'">

    Pepe Baño: <input type="radio" name="'.$idperro.'/servicio" value="'.$idperro.'/baño/'.$baño.'">
    Pepe Corte: <input type="radio" name="'.$idperro.'/servicio" value="'.$idperro.'/corte/'.$corte.'">
    
    <p id="precio"></p>
';
?>

Heres the HTML output for that:

Jack baño: <input type="radio" name="8/servicio" value="8/baño/260.00">
Jack Corte: <input type="radio" name="8/servicio" value="8/corte/300.00">
Pepe baño: <input type="radio" name="17/servicio" value="17/baño/260.00">
Pepe Corte: <input type="radio" name="17/servicio" value="17/corte/300.00">
<p id="precio"></p>

I am trying to get the value of the selected radio button, but I cant set the name in Jquery in this fashion. (consider the var $idperro the dynamic var below. I know thats not the correct format for jquery and ive tried many things)

$("input[name=$idperro/servicio]").filter(":checked").val();

Is there any other way on which i can set a javascript function or jquery to get it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could try something like this.

Add a class yourClassName for easy targeting with jQuery:

Jack baño: <input class="yourClassName" type="radio" name="8/servicio" value="8/baño/260.00">
Jack Corte: <input class="yourClassName" type="radio" name="8/servicio" value="8/corte/300.00">
Pepe baño: <input class="yourClassName" type="radio" name="17/servicio" value="17/baño/260.00">
Pepe Corte: <input class="yourClassName" type="radio" name="17/servicio" value="17/corte/300.00">
<p id="precio"></p>

Then you could try:

$("input.yourClassName:checked").val();
about 4 years ago · Juan Pablo Isaza 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