Click to See Complete Forum and Search --> : variable in command


foggydyde
07-21-2003, 02:32 PM
Maybe this question is dumb, but I am more used to php than javascript. besides, there is more chance to a usefull answer on a simple rather than on a difficult question ;)

this is my problem:

For my script that is used to enter news- or questbook entries I want to add a feature like PHB/yabb code. So i made buttons based upon the yabb source. thos burrons add the code into the textarea.:

function AddText(text,field)
{
document.form.message.value += text;
}


here, the name of the field is 'message'.

but now i want it to be the string of variable "field". how do i make that? this is not working:

function AddText(text,field)
{
document.form.+ field +.value += text;
}



please help me with this, how do I add a variable into my command?

Exuro
07-21-2003, 02:39 PM
Try this:
document.form.elements[field].value += text;

foggydyde
07-21-2003, 02:44 PM
thank you very much, it is working fine now. so to input a variable, one has to typ:

blah.blah.elements[variable].blah etc?