0

My index.html

<div id="dropDownBolumDiv" class="dropdown-menu" x-placement="bottom-start" style="position: absolute; transform: translate3d(0px, 38px, 0px); top: 0px; left: 0px; will-change: transform;">

</div>

<script>
     var parameterYil = document.getElementById("dropDownYil1").value;
     var bolumler = ["ELEME MAKİNALARI", "ELEVATÖR", "EXCELL", "FOTOSORTER"];
     for (i = 0; i < bolumler.length; i++) {
         $("#dropDownBolumDiv").append("<a class='dropdown-item' onclick='refreshCharts(parameterYil,"+bolumler[i]+")'>" + bolumler[i] + "</a>");
     }
</script>

For example : when I clicked EXCELL,nothing happen.And console error says;

Uncaught ReferenceError: EXCELL is not defined at HTMLAnchorElement.onclick

What is problem ?

1 Answer 1

1

wrap bolumler's units in single quotes(') to make them string, not identifier

bolumler.forEach(v => {
         $("#dropDownBolumDiv").append(`<a class='dropdown-item' onclick='refreshCharts(parameterYil,"${v}")'>${v}</a>`);
     })
Sign up to request clarification or add additional context in comments.

4 Comments

I changed and result : <a class="dropdown-item" onclick="refreshCharts(2019," eleme makİnalari')'>ELEME MAKİNALARI</a> so dont work
Then just use not a single qoute but double qoutes with \ before it refreshCharts(parameterYil,\""+bolumler[i]+"\")
sorry, I changed my answer, i checked - this way it works
don't work but no problem. I'll still mark it as an answer.Thank you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.