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

396
Views
how to call id with value <?php echo $ ?> in javascript

i have div with id like this

<div id='alert<?php echo $row['no']?>'>
<b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b>
</div>

and i need to call that id in javascript,

i try like this but the value not right

$("#alert<?php echo $row['no'] ?>").hide();

how to fix it

thankyou

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to include jQuery CDN

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

<script>
   $("#alert<?php echo $row['no'] ?>").hide();
</script>
about 4 years ago · Juan Pablo Isaza Report

0

I'm assuming that you have something like this:

foreach($result as $row){
  ?>
  <div id='alert<?php echo $row['no']?>'>
    <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b>
  </div>
  <script>$("#alert<?php echo $row['no'] ?>").hide();</script>
  <?php
}

Otherwise if the script-tag is outside the loop then it wount work. Another solution would be to make a function let say hideAlert(div) and do something like this:

<?php

foreach($result as $row){
  ?>
  <div onload="hideAlert(this)">
    <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b>
  </div>
  <?php
}
?>

<script>
  function hideAlert(div){
    div.hide();
  }
</script>

if you need the id to reference to it later you could just change the code like this:

foreach($result as $row){
  ?>
  <div onload="hideAlert(<?php echo $row['no']; ?>)">
    <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b>
  </div>
  <?php
}
?>

<script>
  function hideAlert(id){
    $(`#alert${id}`).hide();
  }
</script>

Keep in mind that I'm not an expert on jQuery soo I'm not really sure if this works but i hope it helps :)

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!