As an extension of this question, I'm trying to insert Javascript to a <h:commandButton />
's onclick
property as action
is already rendering an ajax table.
What I want to do:
Get the selected items in a list box and turn them into parameters to be used in a JSF FileServlet
. i.e. para2=value1¶m=value2¶m=value3
Here's what I have:
<script type ="text/javascript">
function myScript() {
var box = document.getElementbyId('myForm:box');
var length = box.options.length;
var paramstring = "";
for (var i = 0; i < length; i++) {
if (i != (length - 1) {
if (box.options[i].selected) {
paramstring = paramstring + "param=" + box.options[i].value + "&";
}
} else {
paramstring = paramstring + "param=" + box.options[i].value;
}
}
if (document.getElementById('myForm:checkbox').checked) {
window.location='fileServlet? + paramstring;
}
}
</script>
What I get when page is loaded:
javax.servlet.ServletException: Error Parsing /page.xhtml: Error Traced[line:15] The content of elements must consist of well-formed character data or markup.
What doesn't trigger exception:
<script type ="text/javascript">
function myScript() {
var box = document.getElementbyId('myForm:box');
var length = box.options.length;
var paramstring = "";
if (document.getElementById('myForm:checkbox').checked) {
window.location='fileServlet? + paramstring;
}
}
</script>
As soon as I add in for (var i = 0; i < length; i++)
or even for (var i = 0; i < 10; i++)
the page wouldn't load. Why does it not like the for loop?
<![CDATA[
block or using an external js file. I shortened the code formyScript()
towindow.location='fileServlet?param=1';
, and this only runs if I put it inline withonclick
or in<script type="text/javascript"></script>
– Outdo