Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to tackle getElementById vs a loop in php
    primarykey
    data
    text
    <p>please guide me in right direction if you can. </p> <p><strong>My Situation</strong></p> <p>I have a script that pulls data in a <code>PHP</code> for loop. In that loop there is a parameter called <code>Price</code>.In the same loop im using a javascript function to convert the <code>Price</code>, from <code>Jap Yen</code> to <code>Aus Dollars</code> and finally display the price in <code>Aus Dollars</code>.</p> <p><strong>Problem</strong></p> <p>Im using <code>getElementById</code> to show the Price in AUD and here's my js funciton</p> <pre><code>function CarCostCalculatorSINGLE(enteredPriceInYen,spanID){ document.getElementById("calPriceInAudSINGLE"+spanID).innerHTML="$"+TotalCarCostInAUD.formatMoney(0, '.', ','); } </code></pre> <p>And in my php script, Im using a counter to add a number to the end of the span so the <code>IDs</code> don't clash.</p> <pre><code>$callPriceInAudCounter++; &lt;span id="calPriceInAudSINGLE&lt;?php echo $callPriceInAudCounter; ?&gt;"&gt;AUD Price Goes Here&lt;/span&gt; &lt;script&gt; CarCostCalculator(&lt;?php echo $fields['price']; ?&gt;, &lt;?php echo $callPriceInAudCounter; ?&gt;); &lt;/script&gt; </code></pre> <p><strong>Im Lost</strong></p> <p>Im now lost becuase on some pages I have to <code>include</code> loops to show <code>Side bar content</code> etc and the <code>IDs</code> clash bigtime. This is not the best way to tackle this and I have no idea what else I can do to stay in the loop and show the price without duplicating the functions . Is there an alternative to <code>getElementById</code> or can you guys please guide me what's the best way to tackle this? </p> <p>Please tell me if you want me to clarify more, Im more than happy to.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload