1

Urgent..Anyone please Assist how to access data from the elements added via javascript dynamically using the jsp code. i am adding empty records on .jsp page using javascript (by calling a below function on click event of button) as :-

var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.value="";
    cell1.appendChild(element1);            //and so on for 5 columns too

Main problem is that i am not able to access these dynamically added textboxes values from my jsp code. (because they have been created dynamically by javascript)

Now,i want to save the value from these dynamically added textboxes(in form of table) from the .jsp page to database using jsp...(there can be several rows generated depending upon user input) or else suggest me code to create them dynamically so that i can fetch data from added dynamic textboxes on jsp page. And please ..i don't want to go for servlet concept...wants using jsp only..

thnks ....

2 Answers 2

1

Why dont you provide unique id and name to the textboxes you are adding?

var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.value="";
    element1.id="empName[0]";
    element1.name="empName[0]";

cell1.appendChild(element1); 

Like

<input type="text" id="empName[0]" name="empName[0]" value=""/>
<input type="text" id="empName[1]" name="empName[1]" value=""/>

Then on server side you can,

request.getParameter("empName[0]");
request.getParameter("empName[1]");
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 var textboxes = [];
 var inputs = cell1.getElementsByTagName('input');
 for(var i = 0; i < inputs.length; i++){
     if(inputs[i].type == "text")
          textboxes.push(inputs[i]);
          // or get name value pairs if not disabled: 
          // if(!inputs[i].disabled)
          //     myNameValues.push({ name: inputs[i].name, value: inputs[i].value });
 }

1 Comment

thanks a lot guys for your assistance... thanks The 1 again..it's working. even it resolved my doubts too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.