Dynamically name form fields

View: New views
2 Messages — Rating Filter:   Alert me  

Dynamically name form fields

by Dave Hannum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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");
        var PX = eval("document.CFForm_1.cellP_"+ct+".value");
        var SX = eval("document.CFForm_1.cellS_"+ct+".value");
        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.fusionauthority.com/quarterly

Archive: http://www.houseoffusion.com/groups/Javascript/message.cfm/messageid:3264
Subscription: http://www.houseoffusion.com/groups/Javascript/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33

Re: Dynamically name form fields

by Peter Boughton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You do it exactly the same way as you are for the a11 and a12 bits.
ie: Give each form element a unique id and then do:
var AC = document.getElementById('cellA_'+ct).value;
etc.

And if you don't like typing document.getElementById millions of
times, just create a shortcut function:
function elem(ent){return document.getElementById(ent);}

On 10/19/06, David Hannum <oujasper@...> wrote:

> 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");
>        var PX = eval("document.CFForm_1.cellP_"+ct+".value");
>        var SX = eval("document.CFForm_1.cellS_"+ct+".value");
>        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.fusionauthority.com/quarterly

Archive: http://www.houseoffusion.com/groups/Javascript/message.cfm/messageid:3265
Subscription: http://www.houseoffusion.com/groups/Javascript/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33