Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP Array with Javascript and variable label id
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Skythrust" data-source="post: 470397" data-attributes="member: 87030"><p>Hi there!</p><p></p><p>I am learning again new stuff, and I am trying to find a solution to use a JSON Array with JavaScript/variable label id.</p><p></p><p>every record in the array does have an icon value (for example 1,2 or 3), First text and a second text. Every record does need his own label id value to use this code below.</p><p></p><p>I have searched a long time on the internet, but I got stucked in the codes, and I have no idea where I need to start :-(. the following step is to change the JSON array directly to a SQL Server Database.</p><p></p><p>JSON Array:</p><p>[CODE=json]$json = '[{"Id":"1","Icon":"1","FName":"Facebook","Sname":"ThisPasswordIsSecret"},{"Id":"2","Icon":"2","FName":"Instagram","Sname":"ThisPasswordIsSecret"},{"Id":"7","Icon":"3","FName":"Twitter","Sname":"ThisPasswordIsSecret"},]';[/CODE]</p><p></p><p>PHP Code (plain HTML)</p><p>[CODE=html]<body></p><p> <div class="flip"></p><p> <div class="card"></p><p> <div class="face front"></p><p> <img src="IMAGEID" /></p><p> <div class="label" id="label">Facebook</div></p><p> <button class="viewbtn" onclick="changeLabel()">&#128275;</button></p><p> </div></p><p> </div></p><p> </div> </p><p> </body></p><p></html></p><p></p><p><script></p><p> function changeLabel() {</p><p> let label = document.getElementById('label');</p><p> label.innerText = "ThisPasswordIsSecret";</p><p> setTimeout(function(){ document.getElementById("label").innerHTML = 'Facebook';}, 3000);</p><p> </p><p> }</p><p> </p><p></script>[/CODE]</p><p></p><p>Thanks in advance!</p><p>[automerge]1628505328[/automerge]</p><p>I have found the way for the class id, only now is the script left. I was assuming that I could realize this on this way. But it doesn't work.</p><p></p><p>[CODE]<?php</p><p></p><p>$json = '[{"Id":"1","Icon":"1","FName":"Facebook","Sname":"ThisPasswordIsSecret"},{"Id":"2","Icon":"2","FName":"Instagram","Sname":"ThisPasswordIsSecret"},{"Id":"7","Icon":"3","FName":"Twitter","Sname":"ThisPasswordIsSecret"}]';</p><p>$array = json_decode($json, true);</p><p></p><p>?></p><p></p><p><?php foreach ($array as $record) { ?></p><p> <div class="flip"></p><p> <div class="card"></p><p> <div class="face front"></p><p> <img src="https://lh3.googleusercontent.com/XDScQo39jp9nk8kzAY_GOGYkb999mmMIqQGacISVnkGNc-tnZDZ1lD4valDhPOz7wxTm3pgk=s50-h50-e365" /></p><p> <div class="label2" id="<?php echo "label".$record['Id']; ?>"><?php echo $record['FName']; ?></div></p><p> <button class="viewbtn" onclick="changeLabel()">&#128275;</button></p><p> </div></p><p> </div></p><p> </div> </p><p> </p><p><script></p><p> function changeLabel() {</p><p> let label = document.getElementById('<?php echo 'label'.$record['Id']; ?>');</p><p> label.innerText = "test";</p><p> setTimeout(function(){ document.getElementById('<?php echo 'label'.$record['Id']; ?>').innerHTML = 'Works';}, 3000);</p><p> </p><p> }</p><p> </p><p></script></p><p></p><p> <?php } ?>[/CODE]</p></blockquote><p></p>
[QUOTE="Skythrust, post: 470397, member: 87030"] Hi there! I am learning again new stuff, and I am trying to find a solution to use a JSON Array with JavaScript/variable label id. every record in the array does have an icon value (for example 1,2 or 3), First text and a second text. Every record does need his own label id value to use this code below. I have searched a long time on the internet, but I got stucked in the codes, and I have no idea where I need to start :-(. the following step is to change the JSON array directly to a SQL Server Database. JSON Array: [CODE=json]$json = '[{"Id":"1","Icon":"1","FName":"Facebook","Sname":"ThisPasswordIsSecret"},{"Id":"2","Icon":"2","FName":"Instagram","Sname":"ThisPasswordIsSecret"},{"Id":"7","Icon":"3","FName":"Twitter","Sname":"ThisPasswordIsSecret"},]';[/CODE] PHP Code (plain HTML) [CODE=html]<body> <div class="flip"> <div class="card"> <div class="face front"> <img src="IMAGEID" /> <div class="label" id="label">Facebook</div> <button class="viewbtn" onclick="changeLabel()">🔓</button> </div> </div> </div> </body> </html> <script> function changeLabel() { let label = document.getElementById('label'); label.innerText = "ThisPasswordIsSecret"; setTimeout(function(){ document.getElementById("label").innerHTML = 'Facebook';}, 3000); } </script>[/CODE] Thanks in advance! [automerge]1628505328[/automerge] I have found the way for the class id, only now is the script left. I was assuming that I could realize this on this way. But it doesn't work. [CODE]<?php $json = '[{"Id":"1","Icon":"1","FName":"Facebook","Sname":"ThisPasswordIsSecret"},{"Id":"2","Icon":"2","FName":"Instagram","Sname":"ThisPasswordIsSecret"},{"Id":"7","Icon":"3","FName":"Twitter","Sname":"ThisPasswordIsSecret"}]'; $array = json_decode($json, true); ?> <?php foreach ($array as $record) { ?> <div class="flip"> <div class="card"> <div class="face front"> <img src="https://lh3.googleusercontent.com/XDScQo39jp9nk8kzAY_GOGYkb999mmMIqQGacISVnkGNc-tnZDZ1lD4valDhPOz7wxTm3pgk=s50-h50-e365" /> <div class="label2" id="<?php echo "label".$record['Id']; ?>"><?php echo $record['FName']; ?></div> <button class="viewbtn" onclick="changeLabel()">🔓</button> </div> </div> </div> <script> function changeLabel() { let label = document.getElementById('<?php echo 'label'.$record['Id']; ?>'); label.innerText = "test"; setTimeout(function(){ document.getElementById('<?php echo 'label'.$record['Id']; ?>').innerHTML = 'Works';}, 3000); } </script> <?php } ?>[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP Array with Javascript and variable label id
Top