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

174
Views
How to set two values to one html button

I'm working on a page where i'm rendering data from an api, where i make dynamic profile cards. And on clicking the button inside the card i'm calling an api through ajax. my problem is i need two values to pass to req.body to make the ajax success. I mananged the api call using one data using this code,

<div class="container" id="bb1">
        <% locals.posts.rows.forEach(function (patient) { %>
            
            <div class="patient-data">
              <div >
                <div style="padding-left: 100px"> <img src="<%= patient.dp %>" style="width: 45%;">  </div>
                <br>
              <div style="text-align: center;">
                <h5> P.ID : <%= patient.p_id %></h5>
                <p>  Name : <%= patient.patient_name %></p> 
              </div>
                <div style="padding-left: 110px;margin-bottom:20px ;"> 
                  <button type = "button" id="<%= patient.p_id %>" onclick="approve(this.id)" type="button" class="btn btn-info btn-sm" id="btn-success" style="background-color: #D1B147;"> View</button> </a></div>
              </div>
                </div>
        <% }); %>
      
    </div>

then inside my script;

<script type="text/javascript">
  function approve(id) {
      var p_id = id;
      console.log(p_id);
      var data = {};
      data.p_id = p_id;

      $.ajax({
            type: 'POST',
            data: JSON.stringify(data),
             contentType: 'application/json',
             dataType: 'json',
             url: "http://localhost:5000/mData",                      
             success: function(data) {
                 console.log(data);
                 localStorage.setItem('myData', JSON.stringify(data));
                window.location.href = 'mastersessionhistory';
                },
                
              error: function(){
                alert("Error")
                console.log('error occured')
              }
        })
   }    
 </script>

using this i was able to hit api and return values. i needed only the p_id to hit api. But now i have new key m_id to so my req.body should be {p_id,m_id}. How to include m_id on that bitton click so that i can call the api. can i use this

<button type = "button" id="<%= patient.p_id, patient.m_id%>" onclick="approve(this.id)" type="button" class="btn btn-info btn-sm" id="btn-success" style="background-color: #D1B147;"> View</button> </a></div>
about 4 years ago · Juan Pablo Isaza
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!