items[1][quantity]: "document has no properties"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maminx
    New Member
    • Jul 2008
    • 77

    #1

    items[1][quantity]: "document has no properties"

    hello all, i have this html below


    [HTML]<input type="text" name="items[1][quantity]" size="3" value="1" onchange="javas cript:showNameO bject();"/>
    [/HTML]
    and i want to alert that object of name with this script

    Code:
    <script language="javascript">
     var form = document.forms[0];
    function showNameObject() {
         alert(form.items[1][quantity].name);
    }
    </script>
    but the browser shown an error "document has no properties..."

    any advice please...???tha nks
    Last edited by acoder; Jul 18 '08, 10:20 AM. Reason: Added [code] tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    I think name items[1][quantity] is not valid.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Why don't you explain what you are trying to achieve first.

      Comment

      • maminx
        New Member
        • Jul 2008
        • 77

        #4
        Originally posted by r035198x
        Why don't you explain what you are trying to achieve first.
        actually i have the function to create an element (input, textarea, and select option)..
        and it's generated by looping..of course to make a name and id of that element that i've created is by array..This is the snipped of that function

        [CODE=javascript] function create_itemized _fields()
        {
        var form = document.forms[0];
        // add a new counter to item_count, which tracks the current number of items.
        item_count++;
        if (item_count <= <?php echo DetailRowMax?>) {//DetailRowMax value could be changed at config.php
        var row = document.create Element('tr');
        row.setAttribut e('id', 'item'+item_cou nt);

        var td = document.create Element('td');
        var p = document.create Element('p');
        var label = document.create Element('label' );
        var span = document.create Element('span') ;
        var theData = document.create TextNode('Pra BP No.');
        var theInput = document.create Element('input' );
        theInput.setAtt ribute('type', 'text');
        theInput.setAtt ribute('name', 'items['+item_count+'][quantity]');
        theInput.setAtt ribute('size', '3');
        theInput.setAtt ribute('class', 'requiredfield' );
        theInput.setAtt ribute('value', item_count);
        //theInput.setAtt ribute('onkeyup ', 'recalculate_it ems();');
        span.appendChil d(theData);
        label.appendChi ld(span);
        label.appendChi ld(theInput);
        p.appendChild(l abel);
        td.appendChild( p);
        row.appendChild (td);
        }else { alert("test");
        }
        }

        [/CODE]
        so, have any idea?
        Last edited by acoder; Jul 18 '08, 10:21 AM. Reason: Added [code] tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Please enclose your posted code in [code] tags (See How to Ask a Question).

          This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use [code] tags in future.

          Also, remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

          This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

          MODERATOR

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by maminx
            and i want to alert that object of name with this script

            Code:
            <script language="javascript">
             var form = document.forms[0];
            function showNameObject() {
                 alert(form.items[1][quantity].name);
            }
            </script>
            but the browser shown an error "document has no properties..."
            If this is the error, that means the error is on the line before the function: var form=document.f orms[0]. The document is not ready. Make sure the line is inside the function or called after the page has loaded.

            PS. use the type attribute for the script tag. The language one has been deprecated.

            PPS. and yeah, form.items[i][quantity] is incorrect syntax, but we can deal with that later.

            Comment

            • maminx
              New Member
              • Jul 2008
              • 77

              #7
              Originally posted by acoder
              If this is the error, that means the error is on the line before the function: var form=document.f orms[0]. The document is not ready. Make sure the line is inside the function or called after the page has loaded.

              PS. use the type attribute for the script tag. The language one has been deprecated.

              PPS. and yeah, form.items[i][quantity] is incorrect syntax, but we can deal with that later.

              ok thanks a lot sir

              kind regard, mamin

              Comment

              Working...