Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refer variables declared in Javascript from within the Servlet

 
Prashil Virgincar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working with HTML5, Javascript and Java Servlets.

I have an HTML code which requests the user to enter a number. Based on what number the user enters, I create those many number of text fields on the HTML page from Javascript as below (below is a sample code which is near to the original code what I am implementing):

HTML:

<b> How many names to be entered?
<input type="number" name="nofield" id="nofield" value="0" required="required" width="7" onchange="showdata()"/>
<br>

<table border="0" id = "table1">
</table>


Javascript:

function showdata()
{
var val= document.getElementById("nofield").value;
var tab = document.getElementById("table1");

var i=1;
for(i=1;i<=val;i++)
{
var oRow = tab.insertRow(-1);
var oCell=oRow.insertCell(-1);
oCell.innerHTML = "<b>Name";
var oCell=oRow.insertCell(-1);
oCell.innerHTML = "<input type=\"text\" name=\"name1\" id=\"name1id\">";
var oCell=oRow.insertCell(-1);
oCell.innerHTML = "<b>Here I am";

}

}


Now, what I want to do is, I want to refer to the cell name (name1) which i declared in the Javascript code from within the servlet. Is there a way to do this ??? I want to refer to this variable content from using a Servlet by calling the function: getParameter(). I am currently getting a NULL value (which is obvious i guess)

I will be providing random names i.e. names like name1, name2, name3 and so on depending upon the number the user specifies.
 
Prashil Virgincar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh god !!! Stupid me !

I was using the "id" instead of "name" attribute in the servlet function getParameter().

The code is working.

thanks for all who made the effort to solve my issue.

I really like this forum
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Good, you were able to rectify it yourself.
But UseCodeTags from next time onwards.

Vishal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic