Dynamically add new entries to a form with buttons

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
illes
Forum Newbie
Posts: 4
Joined: Tue Mar 08, 2005 4:30 pm

Dynamically add new entries to a form with buttons

Post by illes »

Hi,

I've searched the forum with different keywords and also googled an hour, but I coudn't find a solution.
Basically I would like to create a form, initially only with one textfield.

Code: Select all

<input type=&quote;text&quote; name=&quote;name1&quote; value=&quote;&quote;>
Is there a possibility to add new entry, a new textfield with an 'Add new' button? There is a max number of text boxes stored in a variable.

Code: Select all

<input type=&quote;text&quote; name=&quote;name1&quote; value=&quote;&quote;><input type=&quote;text&quote; name=&quote;name2&quote; value=&quote;&quote;>
Also I would like to have a 'Delete' button, which changes hides an entry and when the form is processed, it deletes the entry from the database.

Is this possible with client-side programming (Javascript) with layers (show, hide)?

Thanks for your help in advance.

BR,
Illes
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there are no layers or any real trickery involved. You create a new HTMLFormElement and add it to the form you're dealing with.

DevGuru has some details about this.


Moved to Client-side. :roll:
illes
Forum Newbie
Posts: 4
Joined: Tue Mar 08, 2005 4:30 pm

Thanks

Post by illes »

Dear Feyd,

thanks a lot for your reply, unfortunately this information wasn't enough for me "to show the path".

Could you give me a closer hint?

Thanks,
Illes :wink:
psychomachine
Forum Newbie
Posts: 17
Joined: Wed Mar 03, 2004 1:18 pm

Post by psychomachine »

hi iles.

did you ever figure this out? i am looking for EXACTLY the same solution, but i'm still such a bozo that i can't do it...

all best,
tench
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you guyz get yourself a good book/manual on JS/DOM scripting and try to sort it out yourself. this stuff is not so hard as you think :)
psychomachine
Forum Newbie
Posts: 17
Joined: Wed Mar 03, 2004 1:18 pm

Post by psychomachine »

n00b Saibot -- do you really think that you advice to get a book/manual is helpful? :roll:

my experience with web forums is that there's usually somebody who is willing to share their knowledge, which is great. sometimes questions don't get any answers, which is also understandable. i would never start bitching if my question didn't get answered. that would be rude.

but i really don't think that "get a book", "we're too busy to deal with beginners" and "gee, you're question is so simple, you must be a lazy bastard" type of answer is necessary. unless you really want to rub it in our faces that you know something which we don't.

all best,
tench
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

with out writing the code for you what you need to do is.

1)add an onClick event to your button to call some javascript.
2) in your javascript you need to do something like

Code: Select all

newInputBox = '<div id =&quote;some_sequential_number&quote;><input type=&quote;text&quote; name=&quote;somename&quote; id=&quote;someId&quote; value=&quote;&quote; />';</div>
tempStore = document.getElementById(id).innerHTML
document.getElementById(id).innerHTML = tempStore + newInputBox;
It will be a little tricky to keep unique id's but there are ways around this too.

This will hopefully get your started on what you need.

the key bit is the innerHTML and the running of the DOM, document object model.

phpScott
psychomachine
Forum Newbie
Posts: 17
Joined: Wed Mar 03, 2004 1:18 pm

Post by psychomachine »

thanks a lot scott!
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

psychomachine wrote:n00b Saibot -- do you really think that you advice to get a book/manual is helpful?
Why 8O aren't the books supposed to teach you something :lol: I only suggested that so that you get a good understanding on the subject not rubbing in your face as ou put it :roll:
As Feyd has suggested you before... there are numerous sites out there that are more than willing to help you in all ways to sort your problems/understandings/grounding out. I think that 'getting a book' is an advice.. rest of your enumerations are but a sarcastic remarks and nothing else...
Hope you get my point...
illes
Forum Newbie
Posts: 4
Joined: Tue Mar 08, 2005 4:30 pm

Thanks for your help

Post by illes »

Thanks a lot, I will check it.
Post Reply