Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

plain js version of this php file JavaScript

  • SOLVED

I would like to have a plain js version of this php file:


<ul id="sortable_1" >

<?php

for ($i = 0; $i <= $limit; ) {

echo '<li onmouseup = "play_click();" class="ui-state-default" id = "I' .$i .'"';
echo '></li>';
$i++;
print "\n";
}

?>

</ul>

Answers (1)

2019-07-14

Rainner Lins answers:

Something like this?

https://jsfiddle.net/rainnerlins/utdsnb32/

I set the limit to 20, but you'll probably need to move that over from your PHP code to JS some how.

I assume you're trying to initialize an sortable list from this. Since the list is being rendered on the client side now with JS, make sure to initialize the sortable code after running the code above here to create the list items.


<ul id="sortable_1"></ul>

<script>
// this is just a placeholder, remove as needed
function play_click(elm) {
console.log('clicked on list item ID:', elm.id);
}

// this will select the list above, gerenate the items and place them in the list
let list = document.querySelector('#sortable_1');
let items = '';
let limit = 20;

for (let i = 0; i < limit; i++) {
items += `<li onmouseup="play_click( this )" class="ui-state-default" id="I${i}">Item ${i}</li> \n`;
}
list.innerHTML = items;

</script>


User180435 comments:

screen shows Item ${i} \n`; } list.innerHTML = items;


User180435 comments:

My bad, you were right. I'll check it, though.