Tag Archives: javascript

Count the number of nodes in an XML snippet using Javascript/E4X

Questions: Consider this problem: Using Javascript/E4X, in a non-browser usage scenario (a Javascript HL7 integration engine), there is a variable holding an XML snippet that could have multiple repeating nodes. <pets> <pet type=”dog”>Barney</pet> <pet type=”cat”>Socks</pet> </pets> Question: How to get the count of the number of pet nodes in Javascript/E4X ? EDIT: To clarify, this… Read More »

Handle java object in javascript

Questions: I am using Ajax in my JavaScript and that sets an array of objects of following class in a response: public class RetrieveTempSecVersions { private String templateName; private int[] versionNumber; public String getTemplateName() { return templateName; } public void setTemplateName(String templateName) { this.templateName = templateName; } public int[] getVersionNumber() { return versionNumber; } public… Read More »

How do I pass JavaScript values to Scriptlet in JSP?

Questions: Can anyone tell me how to pass JavaScript values to Scriptlet in JSP? Answers: Your javascript values are client-side, your scriptlet is running server-side. So if you want to use your javascript variables in a scriptlet, you will need to submit them. To achieve this, either store them in input fields and submit a… Read More »

How to open a file using JavaScript?

Questions: I have a servlet that write a pdf file as a ByteArrayOutputStream to the servlet’s output stream. If I open the servlet URL the browser opens the file. But if occur an error on the servlet, the browser opens an empty pdf with an error message. Sending an error through the ServletResponse the browser… Read More »

Javascript: suppress “This page is asking you to confirm that you want to leave” popup on onbeforeunload

Questions: When a user leaves a page, I need to ask him if he wants to perform a particular action before leaving. <script type=”text/javascript”> $(document).ready(function() { window.onbeforeunload = askConfirm; }); function askConfirm() { var addFriend = confirm(“Would you like to ping?”); if (addFriend) { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new… Read More »

Save Base64 String as an Excel .xls file using JavaScript in IE 7

Questions: I have been trying to find a way to save a Base64 String in IE 7 using JavaScript as a Excel .xls file. The following works fine with FireFox: window.open (“data:application/vnd.ms-excel;base64,” + bytestring, “”, “width=300,height=300,resizable=1”); where bytestring is the Base64 string. This method however does not work for IE 7. Having done some internet… Read More »