473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a button that will add text boxes

Hello,

I'm trying to create a javascript function that will allow the user to
press a button within the html code that will add a text box right
above the button. If the user presses it a second time it should add a
second text box right under the previous text box. Any ideas?

Thanks!

Rick

Jan 4 '06 #1
15 1617
Rick escreveu:
I'm trying to create a javascript function that will allow the user to
press a button within the html code that will add a text box right
above the button. If the user presses it a second time it should add a
second text box right under the previous text box. Any ideas?


Use insertBefore :)

<script type="text/javascript">
function add(o){
var i = document.createElement("input"), p = o.parentNode;
i.type = "text", p.insertBefore(i, o),
p.insertBefore(document.createElement("br"), o);
}
</script>

<input type="button" value="New Input" onclick="add(this)" />
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 4 '06 #2
thanks!

what if i want to add a row of three text boxes when the button is
clicked? and my last and final question is how do i assign those
textboxes as part of a sql based database (aka...i want the first
textbox to be "date" the second to be assigned as "name" and the last
to be assigned as "comment")? thank you so much!

Rick

Jan 4 '06 #3
maybe this will help:

the javascript code you posted is great. i want to make it so that
when the button is pressed it outputs something like this:

<table>
<tr>
<td>Date: <input type="text" name="date"></td>
<td>Name: <select name="name"> ***this will be a list from the
database*** </td>
<td>Comment: <textarea class="formfield" style="width: 300"
name=comment"></textarea></td>
</tr>
</table>

is there anyway to recreate that html within the javascript script
function? thanks!

Rick

Jan 4 '06 #4
maybe this will help:

the javascript code you posted is great. i want to make it so that
when the button is pressed it outputs something like this:

<table>
<tr>
<td>Date: <input type="text" name="date"></td>
<td>Name: <select name="name"> ***this will be a list from the
database*** </td>
<td>Comment: <textarea class="formfield" style="width: 300"
name=comment"></textarea></td>
</tr>
</table>

is there anyway to recreate that html within the javascript script
function? thanks!

Rick

Jan 4 '06 #5
maybe this will help:

the javascript code you posted is great. i want to make it so that
when the button is pressed it outputs something like this:

<table>
<tr>
<td>Date: <input type="text" name="date"></td>
<td>Name: <select name="name"> ***this will be a list from the
database*** </td>
<td>Comment: <textarea class="formfield" style="width: 300"
name=comment"></textarea></td>
</tr>
</table>

is there anyway to recreate that html within the javascript script
function? thanks!

Rick

Jan 4 '06 #6
Rick escreveu:
what if i want to add a row of three text boxes when the button is
clicked? and my last and final question is how do i assign those
textboxes as part of a sql based database (aka...i want the first
textbox to be "date" the second to be assigned as "name" and the last
to be assigned as "comment")? thank you so much!


Well, it seems that you want me to do your job hahahaha, but it's ok,
I'm unemployed and today I really have nothing to do, I'm just playing
CS :D

<form id="form">
<input type="button" name="btnAdd" value="New Input" />
</form>

<script type="text/javascript">
(function(){
var o, i, btn, count = -1, p = (btn =
document.forms.form.btnAdd).parentNode;
btn.onclick = function(){
for(i in ++count, {date: 0, name: 0, comment: 0}){
o = document.createElement("input");
o.type = "text";
o.value = o.name = i + count;
p.insertBefore(o, btn);
}
p.insertBefore(document.createElement("br"), btn);
};
})();
</script>

I hope it's what you want...
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 4 '06 #7
Rick escreveu:
i want to make it so that when the button is pressed it outputs something like this:
<table>
:
</table>

is there anyway to recreate that html within the javascript script
function? thanks!


Sure, take a look at my example and make some modifications on your own
;]

It's very simple, basically you'll just need "newNode =
document.createElement(tagName)" and
"parentElement.appendChild(newNode)"...

But you also can create a html string (I always try to avoid using
innerHTML, it looks like the eval function...) and write something
like:

element.innerHTML = "<b>i've got the power to fly into the wind, the
power to be free, to die and live again =]</b>";

Good luck, it's time to eat :]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 4 '06 #8
thanks so much for the help jonas!

im new to this javascript stuff and i thought i could just put my html
right into the script...bad idea...hahaha

thanks again!

rick

Jan 4 '06 #9
thanks so much for the help jonas!

im new to this javascript stuff and i thought i could just put my html
right into the script...bad idea...hahaha

thanks again!

rick

Jan 4 '06 #10
quick question,

when you say "element.innerHTML", do you mean I can put all the html
code that I listed to you within the equal signs after that tag?
thanks!

rick

Jan 4 '06 #11
Rick escreveu:
when you say "element.innerHTML", do you mean I can put all the html
code that I listed to you within the equal signs after that tag?


Yeah, that's it... :)

If you want to add a "<b>" in the end of an element, you can make
something like
element.innerHTML += "<b>aaaa</b>";

PS: try to not send the same message several times, it takes just a
little while to appear :]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 5 '06 #12
JRS: In article <11**********************@g14g2000cwa.googlegroups .com>
, dated Wed, 4 Jan 2006 18:26:39 local, seen in
news:comp.lang.javascript, Jonas Raoni <jo********@gmail.com> posted :

PS: try to not send the same message several times, it takes just a
little while to appear :]


For everybody, the time is non-zero; but all proper news servers will
show a posted article almost immediately. When giving advice
specifically for Google users, please indicate it as such.

Remember : News has been operating for decades; it has developed
effective standards and conventions, and newsreaders and servers that
respect these.

Upstart web-based systems ignore these, to the disadvantage of those who
don't realise that they could be using a properly-designed service.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jan 6 '06 #13
Dr John Stockton said the following on 1/6/2006 11:54 AM:
JRS: In article <11**********************@g14g2000cwa.googlegroups .com>
, dated Wed, 4 Jan 2006 18:26:39 local, seen in
news:comp.lang.javascript, Jonas Raoni <jo********@gmail.com> posted :
PS: try to not send the same message several times, it takes just a
little while to appear :]
For everybody, the time is non-zero;


That is, obviously, not true.
but all proper news servers will show a posted article almost immediately.
That is not always true either. The time it takes to show an article is
based on more than "proper news servers". I use a "proper news servers"
but it does not always "immediately" show a new article. It depends on
server traffic among other things.

And, "almost immediately" is not "non-zero" time.
When giving advice specifically for Google users, please indicate it as such.


That advice applies to other users besides Google users. Even if it is a
Google user that invokes that advice.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 6 '06 #14
JRS: In article <LO********************@comcast.com>, dated Fri, 6 Jan
2006 15:15:42 local, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 1/6/2006 11:54 AM:
JRS: In article <11**********************@g14g2000cwa.googlegroups .com>
, dated Wed, 4 Jan 2006 18:26:39 local, seen in
news:comp.lang.javascript, Jonas Raoni <jo********@gmail.com> posted :
PS: try to not send the same message several times, it takes just a
little while to appear :]
For everybody, the time is non-zero;


That is, obviously, not true.


The article has to travel to some form of news server and back, and be
processed on the sending, serving, and receiving machines. That cannot
happen in zero time.
but all proper news servers will show a posted article almost immediately.


That is not always true either. The time it takes to show an article is
based on more than "proper news servers".


I was writing about proper news servers, as can be told from my use of
those words.
I use a "proper news servers"
but it does not always "immediately" show a new article. It depends on
server traffic among other things.
I wrote "almost" to allow for such things.

And, "almost immediately" is not "non-zero" time.


Of course it is. "Almost immediately" is slower than "immediately"; and
"immediately" implies "subsequently", which tales longer than zero time.

--
© John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jan 7 '06 #15


How about with drop down?

*** Sent via Developersdex http://www.developersdex.com ***
Jan 12 '06 #16

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

Similar topics

2
3389
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
2
5954
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
4
11022
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
1
2899
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
1
9733
by: Jon Smith via DotNetMonster.com | last post by:
Hi all, I have a windows form which contains several text boxes. I would like these text boxes to DataBind to records in an Access.mdb. I have connected to the Access.mdb using ADO.Net. ...
6
3404
by: BurntWithTime | last post by:
Hello everyone, Please can anyone tell me if it is possible for a VB.NET application to check a database and then create textboxes on a form that correspond to those records on the database? For...
2
984
by: gggram2000 | last post by:
Hi, I'm using visual studio 2005, c#. Im having problems creating a print button that will open a word document with the data entered by the user...the user enters his name and so fort in text...
2
1105
by: corinne08 | last post by:
the problem is.... Make a program with two functions. One is to take in records composed of a name and numerical score and store these in a file. The records can be looked up by name to recover...
1
1750
by: dhwanimathur | last post by:
hi all this is my first post in this forum, i am beginner of JSP but since i work in organisation i have to work in Dreamweaver IDE directly instaed of textpad so i need help in creating JSP ...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7114
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.