Click to See Complete Forum and Search --> : [HELP] Duplicating text


yippy
11-08-2003, 03:27 PM
Hi:
i'm trying to have something like this:
when the user type a number in the textbox, other text will duplicate to the number that the user had inputed.
example:

other text (before): a

textbox: 3

othertext (after): aaa

I tried something like a * textbox.value but it gave me NaN

Can someone please help me.... THANK YOU

noahd1
11-08-2003, 06:03 PM
I haven't tested this code or anything....but, something like the below...might have to explicitly cast "formNumber" to an integer.

The + in the for loop is the concatenation operator. In your example a*3 is NaN - NotaNumber.


var othertext = "a";

var formNumber = document.formname.inputname.value;

for (int i = 0; i <= formNumber; i++)
{
othertext = othertext + othertext;
}

yippy
11-09-2003, 10:39 PM
thanx for your advice!
I got it figured out.....


var formNumber = document.formname.inputname.value;
var othertext = 'a';
for (i = 0; i < formNumber; i++)
{
document.write(othertext);
}