Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!