Click to See Complete Forum and Search --> : how do i call this variable?


ai3rules
05-01-2003, 04:05 PM
im just learning javascript, and wrote this small script to practice the for loop. however, i decided to add a bit to it and cant figure out how to call the c variable to the spot i am gonna indicate with a question mark.

function textgenerator()
{
var a = prompt("Enter A Number")
var c = prompt("Enter Size of Box")
for (var b=1; b <= a; b++)
document.write(b+ ". " +"<input type='text' size='?'>" +"<br>")
}

what im trying to do is generate text boxes with a number next to them, depending on the number that is entered in variable a - and that works, however i want to be able to enter a number in variable c and have that affect the size of the text boxes that will be displayed.

i hope someone can help me out - thanks alot.

Shampie
05-01-2003, 04:08 PM
say
c = "embryo"

alert(""+ c + "");

should give message embryo ...

what is with the loop thing?.. where is it used for ?
and what is it used for?

pyro
05-01-2003, 04:13 PM
Try it like this:

function textgenerator()
{
var a = prompt("Enter A Number")
var c = prompt("Enter Size of Box")
for (var b=1; b <= a; b++)
document.write(b+ ". " +"<input type='text' size='"+c+"'>" +"<br>")
}

ai3rules
05-01-2003, 05:46 PM
Originally posted by pyro
Try it like this:

function textgenerator()
{
var a = prompt("Enter A Number")
var c = prompt("Enter Size of Box")
for (var b=1; b <= a; b++)
document.write(b+ ". " +"<input type='text' size='"+c+"'>" +"<br>")
}

hey, it worked - thanks!!