aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes dynamically adding textboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "dynamically adding textboxes" Watch "dynamically adding textboxes" New topic
Author

dynamically adding textboxes

Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Hi all,

I have a requirement to add text boxes in my web page when the user clicks a Button. I explain this very clearly. I have a text box to get "skill of an user". By defaut four text boxes have been given and at the end submit button is given. I have put another button called ADD next to submit button. If user wants to add extra skills, he must click the add button and then a new textbox should appear after the last text box entered. How to do using javascript?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Where's your code? What have you tried so far?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Frankey James
Ranch Hand

Joined: Sep 27, 2008
Posts: 50
Abubacker Siddik wrote:Hi all,

I have a requirement to add text boxes in my web page when the user clicks a Button. I explain this very clearly. I have a text box to get "skill of an user". By defaut four text boxes have been given and at the end submit button is given. I have put another button called ADD next to submit button. If user wants to add extra skills, he must click the add button and then a new textbox should appear after the last text box entered. How to do using javascript?


create a DIV element and assign it an ID where you want the box(es) to appear. use onclick event in ADD button and use AJAX to append the HTML needed in the created DIV container.


ho, ho, ho
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Frankey James wrote:and use AJAX to append the HTML needed in the created DIV container.

Huh, why does Ajax need to be involved? Ajax is not necessary to dynamically create new elements in the DOM.
Frankey James
Ranch Hand

Joined: Sep 27, 2008
Posts: 50
Bear Bibeault wrote:
Frankey James wrote:and use AJAX to append the HTML needed in the created DIV container.

Huh, why does Ajax need to be involved? Ajax is not necessary to dynamically create new elements in the DOM.


true - i guess i thought he would be reading data from a file, but i misunderstood.


so then:
"
create a DIV element and assign it an ID where you want the box(es) to appear. use onclick event in ADD button and use AJAX to append the HTML needed in the created DIV container. "

of course there are other ways.
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Hi james, I dont understand how to append html in the div container. What do you mean by that?
Following is the code you want me to write?


<div id="skillset">
</div>

<input type="button" value="ADD" onclick="javascript:addSkills()"/>

function addSkills(){
//code to get the div element and set the textbox.
}


If so, How to add next skill if it is required??
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

Create new HTML element (input) by

After that just add this element to div element:

Simple as that.
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Thanks Zandis, It is very clear understandable code...


Abu.A
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamically adding textboxes