java - Creating Multiple textboxes dynamically - Stack Overflow

I am making a web application in which I pass a Int value from a servlet to next jsp page like this : r

I am making a web application in which I pass a Int value from a servlet to next jsp page like this :

request.setAttribute("n",n);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/sharingfilesselection.jsp");  
dispatcher.forward(request, response);

Now on the next page i.e sharingfilesselection.jsp I want that n textboxes are created dynamically each with a different id as i need to store the values of these textboxes in my database.

The N is obtained on next jsp page by this :

Object N=request.getAttribute("n");

How this can be done using javascript ?Please help

I am making a web application in which I pass a Int value from a servlet to next jsp page like this :

request.setAttribute("n",n);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/sharingfilesselection.jsp");  
dispatcher.forward(request, response);

Now on the next page i.e sharingfilesselection.jsp I want that n textboxes are created dynamically each with a different id as i need to store the values of these textboxes in my database.

The N is obtained on next jsp page by this :

Object N=request.getAttribute("n");

How this can be done using javascript ?Please help

Share Improve this question asked Apr 8, 2014 at 5:10 user3509463user3509463 592 silver badges7 bronze badges 3
  • stackoverflow./questions/13989741/… i hope this helps you – Saghir A. Khatri Commented Apr 8, 2014 at 5:14
  • @SaghirA.Khatri I want that n textboxes to appear at same time.Not one by one. – user3509463 Commented Apr 8, 2014 at 5:17
  • it is just to give you an idea on how to do it. in your scenario you have to create textboxes in loop. – Saghir A. Khatri Commented Apr 8, 2014 at 5:20
Add a ment  | 

3 Answers 3

Reset to default 3

You can do this using JSTL:

<c:forEach var="i" begin="1" end="${n}">
    Input ${i}: <input type="text" name="txtDynamic_${i}" id="txtDynamic_${i}" />
    <br />
</c:forEach>

Try this in your .javascript

<%String n=(String)request.getAttribute("n");%>
var n=<%=n%>;
for(var i=0;i<n;i++{
   $(".exac").append("<input type="text" id='textbox"+i+"'></input>");
    }
}

.html

<div class="exac">
</div>

Working sample here

html

<div id="container"><input type="button" onclick="createTextBox(5)" value="create textbox">

JS

function createTextBox(n) {

for (var i = 0; i < n; i++) {
    var textBox = document.createElement("input");

    textBox.setAttribute("id", "text_" + i);
    document.getElementById("container").appendChild(textBox);
}}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745403944a4626228.html

相关推荐

  • java - Creating Multiple textboxes dynamically - Stack Overflow

    I am making a web application in which I pass a Int value from a servlet to next jsp page like this : r

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信