Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Text boxes dynamically 1

Status
Not open for further replies.

greyone

Programmer
Dec 14, 2000
200
CA
Hi
I'm writing text boxes to a page dynamically using the following function:
<html>
<head>
<script language=&quot;javascript&quot;>
function AddTextFields(num)
{
data = &quot;&quot;;
data = &quot;<table border=1 width='80%' cellpadding='0' cellspacing='0'>&quot;
+ &quot;<tr><th align='left' bgcolor= '#6699ff' width='20%'>Parameter No.</th>&quot;
+ &quot;<th align='left' bgcolor= '#6699ff' width='40%'>Parameter Name</th>&quot;
+ &quot;<th align='left' bgcolor= '#6699ff' width='40%'>Parameter Value</th></tr>&quot;;

for (i=1; i<=num; i++) {
data = data + &quot;<tr><td><input type='text' size='20%' align='left' id='text'1 name='text'1></td>&quot;
+ &quot;<td><input type='text' size='40%' align='left' id='text'1 name='text'1></td>&quot;
+ &quot;<td><input type='text'size='40%' align='left' id='text'1 name='text'1></td></tr>&quot;;
}
data = data +&quot;</table>&quot;;

layerWrite(&quot;AddParameter&quot;,null,data)
AddParameter.innerHTML=data;
}
</script>
</head>

<body>
<form>
<span id=&quot;AddParameter&quot;></span>
</form>
</body>
</html>

The function takes an argument num which is the number of textboxes.

this works fine but i need to populate the text boxes with different text values. Now since the text boxes a re in a loop how would i pass different values each time.


Please help


s-)
 
hi
whats da problem?
have u tryed 2 create an array with needed text & then in ur loop insert in each box next new value from array?

regards, vic
 
No i have'nt tried this but that's a great idea.
but how do i call the array in the loop.
Do i need to write a function which will create an array of values and then call his function where i specify the value

s-)

please help
 
ok, here is static example:
paste this before ur function
var dattano=new Array(1,2,3,4,5)
var dattaname=new Array('one','two','three','four','five')
var dattavalue=new Array('value_one','value_two','value_three','value_four','value_five')

& this into the function's loop:

for (ii=0; ii<num; ii++) {
data = data + &quot;<tr><td><input type='text' size='20%' align='left' id='text'1 name='text'1 value='&quot;+dattano[ii]+&quot;'></td>&quot;
+ &quot;<td><input type='text' size='40%' align='left' id='text'1 name='text'1 value='&quot;+dattaname[ii]+&quot;'></td>&quot;
+ &quot;<td><input type='text'size='40%' align='left' id='text'1 name='text'1 value='&quot;+dattavalue[ii]+&quot;'></td></tr>&quot;;
}

but what is name='text'1? i think it is a mistake...

if ya want 2 create arrays dynamically, explain a bit more what do u exactly want 2 do, i'll try 2 help u...

regards, vic
 
That was indeed very helpful
but i need to create the arrays dynamically.
Well i want to extract values from the database and i guess poulate it into an array and then call this array in the AddTextFiled function loop.
 
well, i havent any expearence of workin with databases, but i bet there is no big deal with it
smth like
var newArray=new Array()
then, when gettin (somehow) values from a database, write
new_value=//value from db
newArray[newArray.length]=new_value

& ofcourse, u're able 2 do it in the loop...

i gave u the way - go for it, improve ur skills!
 
i just figured out a major problem with this.
Since the array is 0 based and the num parameter starts from 1 how do i extract the 0 value of array
please help
 
i know that was really a stupid question ...i just figured it out myself
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top