Search code examples
liferayportletalloy-ui

Syntax error while passing values in alloy script function


I am dispaying the book details from database. I want to get details of a user who has checked out the book on onclick of the button.

My AUI script:

<aui:script>
        function displayUserDetails(userId,userName)
        {
            var details="<table><tr><td>"+userId+"</td><td>"+userName+"</td></tr></table>";
            AUI().use('liferay-util-window','aui-io-deprecated',function(A)
            {
                var dialog=Liferay.Util.Window.getWindow(
                {
                    dialog: {
                            title:'userdetails',
                            bodyContent:details,
                            centered:true, 
                            modal: true,
                            width: 500,
                            height: 400
                    }
                 }).render();
            });

        }

        </aui:script> 

I am calling the function here

<aui:button name="button9" value="details" id='getMoreInfo_<%=bookId %>' onclick="displayUserDetails(<%=userId %>,<%=un %>);" />

I am getting syntax error that while calling the function on button click (above line)

If i call the function like this...

onclick="displayUserDetails('<%=userId %>','<%=un %>');"

output will be like <%=userId%><%=un%> (in table)

onclick="displayUserDetails(<%=userId %>,<%=un %>);"

Solution

  • Below code is working.....:-)

    onClick='<%="displayUserDetails(\'"+userId+"\',\'"+un+"\');"%>'

    credits to

    Nishikant sapkal @ http://www.liferay.com/community/forums/-/message_boards/message/27640265