Click to See Complete Forum and Search --> : [RESOLVED] Javascript form processing question


ClarkF1
12-03-2006, 01:40 PM
I'm trying to create a css colour switcher which updates the page as soon as a value is selected.

I've got the following javascript function in my page


function changeCol(col,field)
{
if (!DHTML) return;
var x = new getObj(field);
if (col != '')
x.style.color = col;
else
x.style.color = document.change.field.value
}


The user has two options, either select a colour with a button or type in the text code in a text field. The colour is automatically changed when the button is clicked but when the hex code is typed in the user has to click on a change button to change the colour.

col is the new colour
field is the name of the text field which is the same as the div id that will be altered

I want to do this for multiple divs on the same page so I need to change the value of field in 'document.change.field.value' to the value of field

How on earth do I do this?

ClarkF1
12-04-2006, 07:09 PM
Problem solved using eval()


function changeCol(col,field)
{
if (!DHTML) return;
var x = new getObj(field);
if (col != '')
x.style.color = col;
else
x.style.color = eval('document.change.'+field+'.value')
}

Weedpacket
12-05-2006, 04:30 AM
There's also the possibility of using array access:
document.change[field].value