0

I'm trying to pass an onclick event to Javascript using Thymeleaf but getting "Uncaught SyntaxError: missing ) after argument list".

      <li th:onclick="'radar(' + ${radar} + ', ' + ${radarList} + ');'" th:each="radar : ${radarList}" th:id="${radar.index}">
          <button class="button button_module" th:id="${radar.index}">
              <img th:src="@{/images/icon_module_radar.png}" /><br />
              <span th:text="${radar.name}"/>
          </button>
      </li>


function radar(id, list)
{
    for (var i in list)
    {
        document.getElementById(list[i]['index']).className = "button button_module";
    }
    document.getElementById(id['index']).className = "button button_module_selected";

    setRadarStats(id);
}

I think ${radarList} is passing object to list as intended, but I can't see for sure because I'm getting an error.

Any help is much appreciated. Thanks.

1 Answer 1

1

can you replace this line of code

th:onclick="'radar(' + ${radar} + ', ' + ${radarList} + ');'"

with

<li th:onclick="'javascript:radar(\'' + ${radar} +'\',\''+ ${radarList} +  '\');'" 

and let me know if this worked for you

Sign up to request clarification or add additional context in comments.

1 Comment

Well I wanted to avoid using that as that'll parse ${radarList} into string and not object. But I guess there's no other way :(

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.