Learning JS, trying to figure out createelement

Discussion in 'Javascript' started by Ben Hallert, Dec 15, 2004.

  1. Ben Hallert

    Ben Hallert Guest

    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
    making.

    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
    below.

    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 = document.tc.id.length;
    for (var i = 0; i < num; i++)
    {
    if (document.tc.id.checked == true && document.tc.id.type ==
    "checkbox")
    {
    //if it's not the FIRST tcl selected, then create a new hidden
    element named testclass_id
    if (TotalTCLSelected)
    {
    var hidden = document.createElement('input');
    hidden.setAttribute('type','hidden');
    hidden.setAttribute('value',document.tc.id.value);
    hidden.setAttribute('name','testclass_id');
    document.getElementById(document.appendChild(hidden));
    }
    TotalTCLSelected++;
    }
    }
    }

    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
    document.tc.createelement? (where tc is the name of the form being
    parsed)
    3. I didn't define TotalTCLSelected anywhere. It isn't erroring out,
    but could this be silently killing it?
    4. Other?

    Thanks!
     
    Ben Hallert, Dec 15, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Randall Parker

    Trying to figure out forms authentication

    Randall Parker, Dec 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    538
    =?Utf-8?B?VmVua2F0X0tM?=
    Dec 5, 2005
  2. =?Utf-8?B?cm9kY2hhcg==?=

    still trying to figure out datalist event handler

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    288
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 26, 2006
  3. Replies:
    2
    Views:
    536
  4. Replies:
    3
    Views:
    288
    =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Jan 10, 2007
  5. Ben Hallert
    Replies:
    3
    Views:
    74
Loading...

Share This Page