0

I'm trying to pass some string parameters to a jQuery function in my page. My jQuery looks something like this

   function showModal(text1, text2, text3) {
        $('#modal1').text(text1);
        $('#modal2').text(text2);
        $('#modal3').text(text3);
        $('#modal').modal('toggle');
    }

And the line that's calling the function looks something like this

<spring:message javaScriptEscape="true" var="text1"
                            text="${obj1.text}"/>
            <spring:message javaScriptEscape="true" var="text2"
                            text="${obj1.text2}"/>
            <spring:message javaScriptEscape="true" var="text3"
                            text="${obj1.text3}"/>    

<tr onclick="showModal('${text1}, ${text2}, ${text3}');"> 

I get an error in chrome when I click the table row

Uncaught SyntaxError: Unexpected number

1 Answer 1

1

The single quotes in this line:

<tr onclick="showModal('${text1}, ${text2}, ${text3}');">

are delimiting a string, so that you're only passing one argument to the function. Try:

<tr onclick="showModal('${text1}', '${text2}', '${text3}');"> 
Sign up to request clarification or add additional context in comments.

2 Comments

Works! Thank you!
Be sure to accept this answer if it solved your problem @BrijParel.

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.