List Info

Thread: Dynamically name form fields




Dynamically name form fields
user name
2006-10-19 12:06:38
Hello,

I need to populate the value of a dynamically generated form
field name.  But wrapping in an eval() does not work (at
least the way I'm doing it).  Can someone show me how to
properly do this?  Everything works fine down to where I try
to assign the value of "cellPhone" to the
dynamically named form field (the 'eval' line).

function putCell(ct) {
	var AC =
eval("document.CFForm_1.cellA_"+ct+".value&qu
ot;);
	var PX =
eval("document.CFForm_1.cellP_"+ct+".value&qu
ot;);
	var SX =
eval("document.CFForm_1.cellS_"+ct+".value&qu
ot;);
	var cellPhone = AC+"."+PX+"."+SX;
       
eval("document.CFForm_1.document.CFForm_1.phoner_"
+ct+".value") = cellPhone;
	document.getElementById('a11_'+ct).innerHTML = cellPhone;
	document.getElementById('a11_'+ct).style.visibility =
'visible';
	document.getElementById('a12_'+ct).style.visibility =
'hidden';	
}

Thanks,
Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages
of hard-hitting,
up-to-date ColdFusion information by your peers, delivered
to your door four times a year.
http://www.f
usionauthority.com/quarterly

Archive: http://www.houseoffusion.com/groups/Jav
ascript/message.cfm/messageid:3264
Subscription: http://www.houseoffusion.com/groups/Javascript/subsc
ribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/u
nsubscribe.cfm?user=22184.15789.33
Re: Dynamically name form fields
user name
2007-02-01 13:27:09
> Hello,
> 
> I need to populate the value of a dynamically generated
form field 
> name.  But wrapping in an eval() does not work (at
least the way I'm 
> doing it).

You don't need eval, just use your form like a hash instead
of trying to get the values like a property:

var AC = document.CFForm_1["cellA_"+ct].value

--
Pat

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7 
Experience Flex 2 & MX7 integration & create
powerful cross-platform RIAs 
http:http:
//ad.doubleclick.net/clk;56760587;14748456;a?http://www.adob
e.com/products/coldfusion/flex2/?sdid=LVNU

Archive: http://www.houseoffusion.com/groups/Jav
ascript/message.cfm/messageid:3531
Subscription: http://www.houseoffusion.com/groups/Javascript/subsc
ribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/u
nsubscribe.cfm?user=22184.15789.33

Re: Dynamically name form fields
user name
2007-02-01 13:37:07
Oh, and to address the original post's concern, yes, that
method works in assignment as well... either of these two
are valid:

var AC = document.CFForm_1["cellA_"+ct].value
document.CFForm_1["cellA_"+ct].value = AC;

And, since the key value is dynamically created using
whatever formula, you could even use form values (or even
dynamically addressed form values) as part of the field
name:


document.CFForm_1["cell"+document.CFForm_1.phonety
pe.value+"_"+ct].value = cellphone;
document.CFForm_1["cell"+document.CFForm_1["p
honetype_"+ct].value+"_"+ct].value =
cellphone;

of course, if you get crazy with the document.CFForm_1
assignments, it pays to do:

var theForm = document.CFForm_1;

first, to make things less hair-pullingly confusing. 

--
Pat

> I need to populate the value of a dynamically generated
form field 
> name.  But wrapping in an eval() does not work (at
least the way I'm 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7 
Experience Flex 2 & MX7 integration & create
powerful cross-platform RIAs 
http:http:
//ad.doubleclick.net/clk;56760587;14748456;a?http://www.adob
e.com/products/coldfusion/flex2/?sdid=LVNU

Archive: http://www.houseoffusion.com/groups/Jav
ascript/message.cfm/messageid:3532
Subscription: http://www.houseoffusion.com/groups/Javascript/subsc
ribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/u
nsubscribe.cfm?user=22184.15789.33

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )