dmbdnr
dmbdnr

Reputation: 334

How to pass java method return value to JavaScript function in JSP?

I have the following line in my JSP file:

<input type="button" name="btnNew" value="Új" class="button" onClick="clickSubmitButton('newRow'); isRowExists(<%tblMgr.isRowInDueCauseTable(request);%>)">

The isRowInDueCauseTable(request) method is returning a boolean value, but I'm not sure if I'm passing the boolean value to the javascript isRowExists function correctly, because I always get undefined, when I try to evaluate:

function isRowExists( isRowInDatabase ) {
        console.log(isRowInDatabase);
        if (isRowInDatabase == true) {
            alert('Already in database');
        }
    }

How can I pass the java methods return value to the JavaScript function in JSP?

Upvotes: 0

Views: 1033

Answers (2)

Ady Junior
Ady Junior

Reputation: 1080

The correct syntax needs the equal character(=) to write a value.

See:

Incorrect way:

<%tblMgr.isRowInDueCauseTable(request);%>

Correct way:

<%=tblMgr.isRowInDueCauseTable(request)%>

Then:

<input type="button" name="btnNew" value="Új" class="button" onClick="clickSubmitButton('newRow'); isRowExists(<%=tblMgr.isRowInDueCauseTable(request)%>)">

Upvotes: 1

Sonic
Sonic

Reputation: 34

try AJAX, you can set your text(value to return) to request and then read it in javascript function.

Upvotes: 0

Related Questions