aspose file tools*
The moose likes Servlets and the fly likes How to refer variables declared in Javascript from within the Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to refer variables declared in Javascript from within the Servlet" Watch "How to refer variables declared in Javascript from within the Servlet" New topic
Author

How to refer variables declared in Javascript from within the Servlet

Prashil Virgincar
Greenhorn

Joined: Aug 21, 2012
Posts: 8
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

Joined: Aug 21, 2012
Posts: 8
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

Joined: Aug 09, 2012
Posts: 179
Hi,

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

Vishal


Programming is about thinking, NOT coding
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to refer variables declared in Javascript from within the Servlet