I have a javascript file that doing encoding for some string and implement it inside foreach PHP function to get values but unfortunately javascript holding and storing the first value from the foreach function only and keep repeating it
PHP
foreach ($json_content as $index => $array) {
echo '<textarea id="index" style="display:none">'.$index.'</textarea>';
echo '<textarea id="encoded'.$index.'" style="display:none">'.$aa_encode.'</textarea>';
echo '<script type="text/javascript" src="decdoe.js"></script>';
echo '<script type="text/javascript">function();</script>';
}
Javascript
var index = document.getElementById("index");
var AEncoded = document.getElementById("encoded"+index.value);
document.write(index.value);
document.write(function(AEncoded.value));
Output
000
firstvalue/firstvalue/firstvalue
What I missed?
$indexbeside the IDid="index"is not unique. It's duplicated.id="index'.$index.'"but it gave me this errorUncaught TypeError: index is nullin console log