0

I need to call a javascript function inn thymeleaf and I am getting an error as function is not defined. Here's my code

<div class="input-field col s6 m6">
        <input id="isbn" name="isbn" type="text" class="validate" />
        <label for = "isbn">Enter ISBN Code</label>
</div>
    <div class="input-field col s6 m6">
        <button id="submitCode" class="btn waves-effect waves-light col m4" th:onclick="'javascript:myFunction();'" value="data">ISBN Data</button>
    </div>

Javascript Code

function myFunction()
{
    var isbn = document.getElementById('isbn').value;
    alert(isbn);
    var xmlhttp = new XMLHttpRequest();
    var url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn;
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200)
        {
            var x = JSON.parse(xmlhttp.responseText);
            callback(x);
        }
    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
}
function callback(x)
{
    //do things with your data here
    alert(JSON.stringify(x));
    console.log(x);
}
1
  • please share the complete error log, that will help to identify the problem. Commented Dec 10, 2016 at 6:30

1 Answer 1

1

May be you should try th:onclick="'myFunction();'" You can refer this link Javascript function call with Thymeleaf

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

Comments

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.