Reputation: 33
I am trying to submit the value of my onClick to a function. It works properly if the "li" is manually coded. However, it doesn't work if the "li" is in the loop and it was appended in a div.
Here's the code I've already tried:(also tried to change ' to " in oncliclick=myFunction('i'))
<div id="side_menubar">
<ul>
<script>
<? var menu = SpreadsheetApp.openById("id here").getSheetByName("Menu");
var range = menu.getRange("B1:B").getValues();
var lRow = range.filter(String).length;?>
<?for(var i = 2; i <= lRow; i++){?>
$('#side_menubar').append($('<li class="menu" onclick="myFunction('i')"><?= menu.getRange("B" + i).getValues(); ?></li>'))
<? } ?>
function myFunction(x) {
document.getElementById("content_header").innerHTML = "x";
document.getElementById("id01").style.display = "block";
}
</script>
</ul>
</div>
I expect that the value in the onClick should be submitted to the function.
Upvotes: 1
Views: 77
Reputation: 64072
I don't use these very much
but I think this one
$('#side_menubar').append($('<li class="menu" onclick="myFunction('i')">
needs to be like this
$('#side_menubar').append($('<li class="menu" onclick="myFunction(<?=i?>)">
Upvotes: 1
Reputation: 33
Hi Cooper thanks for the idea. It doesn't work but when i change it to this it works:
$('#side_menubar').append($('<li class="menu" onclick="myFunction(<?=i?>)">
I just removed the single quote because I think it breaks or it reads as a closing quote for the li for append.
Upvotes: 0