0

my javascript function is below where I am creating the 2 textboxes dynamically each time when the addRow() function is called on button click.Also,I am setting name attribute for each textbox dynamically.but I am not able to access these textbox values from servlet and getting null value as output.

<html>
<head>
<script>
var count=1;
function addRow()
{


var table = document.getElementById('table');
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.name = "item "+ count;
   // document.write(element1.name);
    cell1.appendChild(element1);     

    var cell2 = row.insertCell(1);
    var element2 = document.createElement("input");
    element2.type = "text";
    element2.name = "amount" + count;
    cell2.appendChild(element2);

    var cell3 = row.insertCell(2);
    cell3.innerHTML = ' <input type="button" value="Edit" onclick="editRow(this)"/><input type="button" value="Delete" onclick="deleteRow(this)"/>';
    cell3.setAttribute("style", "display:none;");

    var cell4 = row.insertCell(3);
    cell4.innerHTML = '<input type="button" value="Save" onClick="saveRow(this)">';


    document.listform.hfield.value=rowCount;
    count++;



}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="css/style.css" type="text/css">
<title>Create your list</title>
</head>
<body>
<form name="listform" method="post" action="Billingservlet">
<div class="wrap">
<center>
<div id="display">
<table id='table' border="0">
<tr id='id'>
<th>
            Item Name
        </th>

        <th>
            No. of units
        </th>   
</tr>   
</table>    

<input type="button" value="Add another item" onclick="addRow()">   
<input type="submit" value="Submit List">
<input type="hidden" name="hfield">

</div>
</center>
</div>
</form>
</body>
</html>
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Can you show how you are trying to read the values? Have you tried using array checkboxes (I think it is something like name="amount[]") – porfiriopartida Sep 13 '13 at 05:43
  • I was reading value in servlet using request.getParameter(amount[1]) but it is giving me null value. – user2773665 Sep 13 '13 at 05:55
  • Then update your question by adding the code. Seems that you are using element1 element2 as names and they can't be accessed by element[1]; you must rename your HTML name to array like if you want to use element[i]. Look at here: http://stackoverflow.com/questions/1978781/how-to-post-multiple-input-type-checkbox-as-array-in-php – porfiriopartida Sep 13 '13 at 08:40

0 Answers0