user5650798
user5650798

Reputation:

Assign variable value in javascript and use in html

How to assign a variable value in javascript and use it in html?

My javascript code:

function validateUrl() {
    var displayButton = "Yes";
}

My html code:

<c:if test="${displayButton == 'Yes' "
</c:if>

How can i use a javsacript variable in my html?

Upvotes: 0

Views: 71

Answers (2)

Holger
Holger

Reputation: 919

This is not HTML, it is a JSTL-Tag.

The code <c:if will be evaluated by the server (glassfish/tomcat) while producing the HTML which will be provided to the browser.

The JavaScript code runs in the browser. There is no (simple) way to use JavaScript values to manipulate HTML-rendering.

HTML itself isn't able to work with JavaScript-variables, so the only way is, to set a variable in JavaScript and use the value with JavaScript.

Upvotes: 1

Marco Klein
Marco Klein

Reputation: 311

You can set data using jquery and $("#display-button").data("key", "Yes") you can read the data out using $("#dispaly-button").data("key") -> returns "Yes"

Upvotes: 0

Related Questions