I want to do a simple thing.
I have a servlet. Inside the DoPost() function I’m writing HTML output to be shown in the browser. This HTML includes a single image. When clicking this image I want to alert its element id.
servlet:
public void printSinglePlayerBoard(int i_PlayerNumber, HttpServletResponse respose)
throws IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>\n");
out.println("<script language='javascript' type='text/javascript'
src='functions.js'></script>\n");
out.println("<body>\n");
out.print("<img id='someID' src='somePath' onclick='func(someID)'/>");
out.print("</form>\n</body>\n</html>\n");
}
functions.js:
function func(someID)
{
alert(someID);
var x = document.getElementById(someID);
alert(x);
}
My problem is that I would like to get the someID String but neither alert(someID) or alert(x) returns my result. What seems to be the problem?
alert(someID) –> returns [Object HTMLImageElement]
alert(x) –> returns null
Does functions.js even recognize the HTML elements created in the servlet?
Thank you!
Change this line
to