0
cell = this.getElementsByTagName("td")[3];
uname = cell.innerHTML;

i get the value of the particular cell through innerHTML and pass that value to Servlet

xmlhttp.open("POST","UserServlet",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("uname="+uname);

in Servlet

uname = request.getParameter("uname");
        out.print(uname);
        System.out.println(uname);

i get "undefined" in console....... is there any way get the value and pass that to servlet i tried .innerHTML,.innerText,.value nothing worked,i tried in array too....but nothing worked......Help me thanks in advance.....

1 Answers1

1

Please refer to https://stackoverflow.com/a/15312976/1031191. That implies that your xmlhttp code is just fine. Try and use javascript console in the browser to verify that uname is a string and contains the right data.

Receiving "undefined" means that the value of uname is exactly "undefined" on the client side. See getParameter's reference: http://docs.oracle.com/javaee/1.3/api/javax/servlet/ServletRequest.html. It says that you must receive either a String or null. (so in your case the argument of xmlhttp.send() is "uname=undefined" for some reason.)

UPDATE 2:

Probably you need document.getElementsByTagName('td')[3] instead of "this".
But hey, if you use jQuery anyway, why don't you write $('td').get(3) instead of getElementsByTagName?

UPDATE 3:

I think you have less than 4 td elements in your html. Please note that javascript arrays are indexed from 0. You receive "undefined" if you accidentally try to access an index in an array that is out of bounds.

Community
  • 1
  • 1
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91