I am using the following JavaScript code to set the value of an element.
document.getElementById('alert['+i+']').innerHTML = "alert";
The element is nested in a Struts set tag. (The ID match up, the fault is not there.)
<s:set var="alert" >
<span id="<s:property value='"alert"+{#stat.index+4}' />"></span>
</s:set>
the set tag var is used by a Struts if tag.
<s:if test="%{#alert == 'alert'}">
//some code
</s:if>
when the span tag is outside of the set tag, the value of the span tag is set to "alert" correctly. However when inside the struts set tag. the span tag cannot be found.
How do I successfully set the value of the set tag? either using the span tag or setting the value of the set tag directly. Or can I somehow inject the "alert" value in the if tag directly?
I have used google and youtube to find answers. I have tried to put the span tag directly in the if tag. I have tried using document.querySelector() but I couldn't get it to work with strut tags.
If you are using
document.getElementById()in JavaScript code, then the element with theidshould be available in the DOM. But it's not available because you put it in the Struts<s:set>tag. It's not UI tag and it doesn't render any HTML elements.You can set the value of
alertvariable in thevalueattribute. It allows to apply an OGNL expression there.Then if you use
<s:if>tag the value of the variablealertshould be found in the context.