Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Learning JS, trying to figure out createelement

Thread Tools

Learning JS, trying to figure out createelement

Ben Hallert
Posts: n/a
Hi there,

I haven't done a lot of Javascript programming, so I'm not having great
luck debugging something I put together, and I was hoping someone here
could give it a quick lookover and maybe see the obvious mistake I'm

My challenge is, I've been asked to make a change to an internal tool.
It has a screen with a tree control and a series of buttons at the top.
The buttons at the top control which form is submitted, and are
enabled/disabled based on what type of things are selected in the tree

It currently uses radio buttons, but I've changed the items that are
parents to be checkboxes instead so I can have multiselect. To
maintain compatibillity with the other forms that expect a single
variable (named testclass_id) to be posted, I've made the following
action to be executed on submit:

function dealWithMultiSelect ()
/*This function should parse through all tcl set checkboxes to see if
there are more then one
//selected. If so, it needs to create a new hidden field with the
same name for each so we can
//send multiple instances of testclass_id to fulfillments review.
//Suggested flow, go through all of the checkboxes and see if there
are more then one active.
//In a sub loop, for each found, add a new hidden field.
//We'll modify set_val to make sure that there isn't a combination of
tcs and tcls set*/
num =;
for (var i = 0; i < num; i++)
if ([i].checked == true &&[i].type ==
//if it's not the FIRST tcl selected, then create a new hidden
element named testclass_id
if (TotalTCLSelected)
var hidden = document.createElement('input');
document.getElementById(document.appendChild(hidde n));

As you can see, I'm trying to use createelement to add more hidden
variables of the same name (in this case, 'testclass_id') so that I'll
be emulating a multi-select GET on the next screen. The intention is
that it loops through all the inputs in the form and, if the item is
checked AND is of the type 'checkbox', it adds a new hidden input with
the value of that item. End result, it should submit multiple
instances of 'testclass_id'. I increment TotalTCLSelected so that it
doesn't start doing that until the second one it encounters on purpose,
that's also to maintain compatibillity with other forms.

Can anyone offer some suggestions? My main theory is that the problem
has to do with one or more of the following:
1. Can I really keep redefining the var hidden in the loop? And does
it get cleared each time?
2. Am I messing up the object inheritance by doing
document.createelement instead of something like (where tc is the name of the form being
3. I didn't define TotalTCLSelected anywhere. It isn't erroring out,
but could this be silently killing it?
4. Other?


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP .NET Beginner trying to figure out <asp:Repeater and checkboxes ASP .Net 2 02-16-2007 05:13 AM
still trying to figure out datalist event handler =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 2 10-26-2006 01:04 PM
Trying to figure out if I can use wireless networking! =?Utf-8?B?QW15?= Wireless Networking 4 08-25-2006 04:35 PM
Trying to figure out forms authentication Randall Parker ASP .Net 2 12-05-2005 08:21 AM
Learning JS, trying to figure out createelement Ben Hallert Javascript 3 12-16-2004 04:45 AM