473,396 Members | 1,982 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,396 software developers and data experts.

Add New Line

I create 10 textfield in tabular form (with loop 10 times). Now I want to
add a button to let user add new line, but I don't have idea/ reference on
how to do this.

Can anyone give me some useful link/ suggestion on this?

Thanks.

Apr 4 '06 #1
3 5622
juicy said on 04/04/2006 11:17 AM AEST:
I create 10 textfield in tabular form (with loop 10 times). Now I want to
add a button to let user add new line, but I don't have idea/ reference on
how to do this.

Can anyone give me some useful link/ suggestion on this?


Insert a BR element where required, say after each 'textfield'?
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 4 '06 #2
Sorry, should be add new textfield.

Currently my solution is put the loop to 20 times,

for(i=0;i<20;i++)
{
if(i>15){//call javascript to set the textfield as hidden}

//create textfield here
}

The disadvantage is these hidden textfield will cause empty space between
10 visible textfield and object below the hidden textfield. And it has
limit the textfield can be add up to 20 only.

Please give suggestion on how to do this or useful links are also
encouraged..as I don't have other idea to solve this...

Thanks.

Apr 4 '06 #3
I'm not that sure what you want to do. Looks like you want to add 5
textfields to an alreddy large set of textfields, and you also want to
"hide" the onces alreddy in the set.

If this is wrong in anyway, you really should try to rephrase your
question.

Anyhow;

I'm guessing you have the textfields in a HTMLelement (div, form, span,
whatever).

// START OF CODE

// First we grab the element the textfields are in, simplest with
getElementById, if the element has a ID attribute.
var textfieldcontainer = document.getElementById("TextFields");

// Then we need all the textfields inside the element.
var textfields = document.getElementsByTagName("input");

// If your container element was a <form> you would now also select the
Submit, Reset buttons so if you did that you must do a check... but I
won't show that.

// First we hide all the elements in the container, even we have
alreddy hidden some we will hide them again.
for (i = 0;i < textfields.length;i++)
{
textfields[i].setAttribute("type","hidden");
}

// Now we create the 5 new textfields. And give them various of
attributes.
var newText1 = document.createElement("input");
newText1.setAttribute("type","text");
newText1.setAttribute("name","whatever");

var newText2 = document.createElement("input");
newText2.setAttribute("type","text");
newText2.setAttribute("name","something");

var newText3 = document.createElement("input");
newText3.setAttribute("type","text");
newText3.setAttribute("name","someone");

var newText4 = document.createElement("input");
newText4.setAttribute("type","text");
newText4.setAttribute("name","pennywise");

var newText5 = document.createElement("input");
newText5.setAttribute("type","text");
newText5.setAttribute("name","theclown");

// And now we add the newly created textfields (appendChild adds to the
end)
textfieldcontainer.appenChild(newText1);
textfieldcontainer.appenChild(newText2);
textfieldcontainer.appenChild(newText3);
textfieldcontainer.appenChild(newText4);
textfieldcontainer.appenChild(newText5);

// END OF CODE

This is a pretty basic way of doing it, but the key here is first we
hide then we add. If we do them at the same time it will just be
harder.

btw:
getElementsByTagName(..) returns a HTMLcollection and not a Array, and
it's Live.
So if you add elements of the same type (as the one grabbed by the
method) you will get referenses to the newly added ones aswell. This
may create never ending loops at times.
juicy wrote:
Sorry, should be add new textfield.

Currently my solution is put the loop to 20 times,

for(i=0;i<20;i++)
{
if(i>15){//call javascript to set the textfield as hidden}

//create textfield here
}

The disadvantage is these hidden textfield will cause empty space between
10 visible textfield and object below the hidden textfield. And it has
limit the textfield can be add up to 20 only.

Please give suggestion on how to do this or useful links are also
encouraged..as I don't have other idea to solve this...

Thanks.


Apr 4 '06 #4

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

Similar topics

8
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.