I have JSP with javascript in the title of it. Script need to be internationalized, so I’m using <fmt:message> tag. I need to put script in a separate file because it looks horrible. Here it is:
<script type="text/javascript">
function check(obj) {
if (confirm("<fmt:message key="body.onsubmit.delete"/>")) {
for( i=0; i<obj.elements.length; i++)
if(obj.elements[i].type=="checkbox"&&obj.elements[i].checked){
return true;
}
alert("<fmt:message key="body.alert.delete"/>");
return false;
}
return false;
}
</script>
Btw, it’s checking checkboxes and gives two type of messages, based on it’s executing, and works good. But the main problem, as I said, is to put it in separate file. So, how could I do it?
I would strongly recommend that you not do this. Use JSP to put strings and other data onto the page, and have your plain JavaScript extract and use it.
To do that, you can use “data-” attributes on elements (like the
<body>element), or<script>blocks with a non-JavaScript “type” attribute, or whatever.