Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create unique ID's for each button in a loop using php echo

I am Having a problem with the button Id id="option_0_0 ,id="option_0_1 and id="option_0_2

Since Now i’m Using echo php, i’m limited to the id’s i can give each button to make each button unique,and the loop keeps repeating the id name on each button, how do create unique ID’s for each button?


<div class="cart">

  <div class="title">Bet Slip</div>
  
  <div id="box" class="boxlit"></div>

  <div>Net Win N$</div>

  <b type="number">300</b>

  <output name="NetWin" for="a b"></output>

  <input type="number" max="100" width="10px">

  <button class="bet1">Bet</button><br />

</div>



<br>

<table id="Table1" class="Fixtures-Table">
    
    <thead>

        <tr>
            
            <th>League</th>
            <th>Home</th>
            <th>Draw</th>
            <th>Away</th>
            <th>Kickoff</th>

        </tr>

    </thead>



    <tbody >

        <tr><th>AFF Women's Championship Group Stage<td id="label" >1<td id="label" >x<td id="label" >2</th></tr>
<tr>
            
                <td class="addItem">Philippines - Australia</td> 
                <td><input type="button" class="decimals" id="option_0_0" value ="20.00" /></td>
                <td><input type="button" class="decimals" id="option_0_1" value ="8.75" /></td>
                <td><input type="button" class="decimals" id="option_0_2" value ="1.04" /></td>
                <td class="label">7/4/2022 13:00</td> 
                
            </tr><tr><th>Africa Women Cup of Nations<td id="label" >1<td id="label" >x<td id="label" >2</th></tr>
<tr>
            
                <td class="addItem">Nigeria - South Africa</td> 
                <td><input type="button" class="decimals" id="option_0_0" value ="2.00" /></td>
                <td><input type="button" class="decimals" id="option_0_1" value ="3.05" /></td>
                <td><input type="button" class="decimals" id="option_0_2" value ="3.45" /></td>
                <td class="label">7/4/2022 19:00</td> 
                
            </tr><tr>
            
                <td class="addItem">Burundi - Botswana</td> 
                <td><input type="button" class="decimals" id="option_0_0" value ="3.65" /></td>
                <td><input type="button" class="decimals" id="option_0_1" value ="3.10" /></td>
                <td><input type="button" class="decimals" id="option_0_2" value ="1.95" /></td>
                <td class="label">7/4/2022 22:00</td> 
                
            </tr><tr><th>Argentina Liga Profesional Argentina<td id="label" >1<td id="label" >x<td id="label" >2</th></tr>
<tr>


this loop is generated from php echo like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

            echo  

            '<tr>
            
                <td class="addItem">'. $row["COL 2"] .'</td> 
                <td><input type="button" class="decimals" id="option_0_0" value ="'. $row["COL 3"] .'" /></td>
                <td><input type="button" class="decimals" id="option_0_1" value ="'. $row["COL 4"] .'" /></td>
                <td><input type="button" class="decimals" id="option_0_2" value ="'. $row["COL 5"] .'" /></td>
                <td class="label">'. $row["COL 6"] .'</td> 
                
            </tr>';
        
        }
        
    
        ?>

>Solution :

I assume you’re asking how to change the id with jquery ? If so then this should do that for you

$(".decimals").each(function(index) {
  $(this).attr("id", index);
});

I hope this helps

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading