Mike D: Don't hate me because I'm posting this here. And don't hate me
because I'm beautiful.

I have a form that's created with CF. Subsequently I add some form elements
via javascript in the classic way, like this:

*var* txtInp = document.createElement('input');
txtInp.setAttribute('type', 'hidden');
txtInp.setAttribute('name', "someName");
txtInp.setAttribute('value', 'someValue');
document.forms[0].appendChild(txtInp);

If I submit the form the "someName" field is there. If I loop through all
the elements and output their names and values, the "someName" element shows
up.

Here's the weirdness. If I try to access it like this:
document.forms[0].someName.value I get a js error telling me it is null or
not an object. I get the same behaviour if I access it like this:
document.forms[0].elements["someName"].value. For whatever reason I can't
directly access it. What I have to do to get to it is loop through all the
form elements, set the given element to a var and compare the name to see if
it's the one I want. If so I can access the value like obj.value. It's the
most ridiculous thing I've ever run into.

I have to turn this:
document.forms[0].someName.value

Into this:
*var* obj;
*for*(*var* i=0;i<document.featured.elements.length;i++) *{*
    obj = document.featured.elements[i];
    *if*(obj.name == "someName")
        var snValue = obj.value;
*}*
This is just so stupid to me. Has anyone else run into this before when
dynamically adding form elements?

Like the pirate with the steering wheel attached to his crotch said: "Yar,
she drives me nuts."


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-community/message.cfm/messageid:300362
Subscription: http://www.houseoffusion.com/groups/cf-community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5

Reply via email to