473,322 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Insert Into Div

I want the ability to add another form element with the click of a
button.

This is what I have now:

<div id="myID"><INPUT TYPE="text" NAME="MyText"></div>
<input type="Button" value="Add Another" onclick="addItem()">

<script>
function addItem() {
myID.innerHTML+='<br><input type="Text" name="MyText">';
}
</script>

It does the job except if you click on the "Add Another" button, it
removes everything you have typed into form fields so far.

Can you use something like document.write to add into a div? Any other
advice?

Thanks for the help.

Jul 23 '05 #1
4 11890
be**********@myway.com wrote:
I want the ability to add another form element with the click of a
button.

This is what I have now:

<div id="myID"><INPUT TYPE="text" NAME="MyText"></div>
<input type="Button" value="Add Another" onclick="addItem()">

<script>
function addItem() {
myID.innerHTML+='<br><input type="Text" name="MyText">';
}
</script>

It does the job except if you click on the "Add Another" button, it
removes everything you have typed into form fields so far.

Can you use something like document.write to add into a div? Any other
advice?

Thanks for the help.


There is a similar question here:
http://groups-beta.google.com/group/...51aa97ba3c490e

:)

Jul 23 '05 #2
In article <11**********************@z14g2000cwz.googlegroups .com>,
be**********@myway.com enlightened us with...

Can you use something like document.write to add into a div? Any other
advice?


Look at DOM methods createElement, appendChild, insertBefore, and insertAfter
instead of innerHTML. A bit more to them, but IME, less problematic in the
long run.
You'd need to create the new form element and append it to the form.

--
--
~kaeli~
Can you be a closet claustrophobic?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
kaeli wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
be**********@myway.com enlightened us with...
Can you use something like document.write to add into a div? Any other
advice?

Look at DOM methods createElement, appendChild, insertBefore, and insertAfter


There is no 'insertAfter' method in DOM Level 2, though the
functionality can be implemented using insertBefore:

node2 = document.createElement(tag);
node1.parentNode.insertBefore(node2, node1.nextSibling)

Where node1 is a reference to some node in the document. node2 will be
inserted after node1 even if it doesn't have a nextSibling.

For the OP, the W3C DOM 2 Core is here:

<URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html>

Useful assistance with examples is provided at the Mozilla site:

<URL:http://www.mozilla.org/docs/dom/domref/>

Remember to feature test before using the DOM's various methods as
support varies in different UAs.

--
Rob
Jul 23 '05 #4
In article <MJ*****************@news.optus.net.au>, rg***@iinet.net.auau
enlightened us with...
kaeli wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
be**********@myway.com enlightened us with...
Can you use something like document.write to add into a div? Any other
advice?

Look at DOM methods createElement, appendChild, insertBefore, and insertAfter


There is no 'insertAfter' method in DOM Level 2,


*smacks self on head*
Thanks.
I should really look stuff up before I post.
Confusing languages again. Sorry.

(note: XmlNode.InsertAfter is a .NET method)

--
--
~kaeli~
Reading while sunbathing makes you well red.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Howard Hinnant | last post by:
I recently asked for a survey of multimap insert with hint behavior, in support of a paper I'm writing concerning lwg issue 233. My sincere thanks to Beman Dawes, Raoul Gough, Russell Hind, Bronek...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
6
by: lenygold via DBMonster.com | last post by:
Hi everybody: What is the best way to I have 10 tables with similar INSERT requiremnts. INSERT INTO ACSB.VAATAFAE WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS ( SELECT AA_TIN,...
1
by: EJO | last post by:
with sql 2000 enterprise Trying to build a stored procedure that will take the rows of a parent table, insert them into another table as well as the rows from a child table to insert into...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.