Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30262
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: How to add/append code to a function? |
| Date | Mon, 11 Apr 2016 22:01:14 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 51 |
| Message-ID | <87egab2739.fsf@bsb.me.uk> (permalink) |
| References | <eb005e58-dab5-4271-bf1d-17f353995725@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="18747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mafN+soKmF3hrd+ssDSHHJy+VhfL1JWA=" |
| Cancel-Lock | sha1:wEQ78n1nawUi5dvay50x6tGEIb4= sha1:7ZEgF6plSv1OL7oEFJ52Kdja2BQ= |
| X-BSB-Auth | 1.6b48a0dea2d84b1f9dca.20160411220114BST.87egab2739.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.javascript:30262 |
Show key headers only | View raw
justaguy <lichunshen84@gmail.com> writes: > I have an HTML page that is heavy with DOM, that is, I have some table > row with several cells, for instance, > [InstrumentName] [Qty] [Person] [OtherInfo] (as one row) > and have a function, say, AddNewRow(), that allows the user to add additional row(s) > Thus, we have > [InstrumentName] [Qty] [Person] [OtherInfo] > [InstrumentName_n] [Qt_n] [Person_n] [OtherInfo_n] > ... > > <span id="newrowFlag"></span> > prior to FORM submission. > > Now, I'd like to allow the user to add additional field(s). Thus, it > may appear like this: > [InstrumentName] [Qty] [Person] [OtherInfo] > +AddField (addField()): > upon click, > Field Name: <input type="text" name="fieldName" size=15> > Field Type: <select name="fieldType"> > <option>Text > <option>Checkbox > </select> > > And if the user did click on addField function, how do we add/append > this addition to the defined AddNewRow function? > > The AddNewRow function's last two lines look like the following: > parentEl.insertBefore(newrow,p); > } > > So, it looks like we need to do two things for the addField function. > (a) dynamically insert the two labels and two fields for a new field. > (b) insert/append new code right before the AddNewRow function's ending } > > Is this the way to go? No. It's better to make things data-driven rather than edit code on the fly (which you can't do in this case anyway). The AddNewRow function should be an action on a form. The AddNewField function should modify that form. AddNewRow uses the form to determine how many things it needs in a row. Of course you might also need to edit existing rows to reflect the presence of the new field. <snip> -- Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to add/append code to a function? justaguy <lichunshen84@gmail.com> - 2016-04-11 12:42 -0700
Re: How to add/append code to a function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-11 22:01 +0100
Re: How to add/append code to a function? justaguy <lichunshen84@gmail.com> - 2016-04-12 16:37 -0700
csiph-web