By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

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

P: 77
hello all, i have this html below


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

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  var form = document.forms[0];
  3. function showNameObject() {
  4.      alert(form.items[1][quantity].name);
  5. }
  6. </script>
  7.  
but the browser shown an error "document has no properties..."

any advice please...???thanks
Jul 18 '08 #1
Share this Question
Share on Google+
6 Replies


dmjpro
100+
P: 2,476
I think name items[1][quantity] is not valid.
Jul 18 '08 #2

10K+
P: 13,264
Why don't you explain what you are trying to achieve first.
Jul 18 '08 #3

P: 77
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

Expand|Select|Wrap|Line Numbers
  1.     function create_itemized_fields()
  2.     {
  3.         var form = document.forms[0];
  4.         // add a new counter to item_count, which tracks the current number of items.
  5.         item_count++;    
  6.         if (item_count <= <?php echo DetailRowMax?>){//DetailRowMax value could be changed at config.php
  7.             var row = document.createElement('tr');
  8.             row.setAttribute('id', 'item'+item_count);
  9.  
  10.             var td = document.createElement('td');
  11.             var p = document.createElement('p');
  12.             var label = document.createElement('label');
  13.             var span = document.createElement('span');
  14.             var theData = document.createTextNode('Pra BP No.');
  15.             var theInput = document.createElement('input');
  16.             theInput.setAttribute('type', 'text');
  17.             theInput.setAttribute('name', 'items['+item_count+'][quantity]');
  18.             theInput.setAttribute('size', '3');
  19.             theInput.setAttribute('class', 'requiredfield');            
  20.             theInput.setAttribute('value',item_count);
  21.             //theInput.setAttribute('onkeyup', 'recalculate_items();');
  22.             span.appendChild(theData);
  23.             label.appendChild(span);
  24.             label.appendChild(theInput);
  25.             p.appendChild(label);            
  26.             td.appendChild(p);
  27.             row.appendChild(td);
  28.              }else { alert("test");
  29.              }
  30. }
  31.  
  32.  
so, have any idea?
Jul 18 '08 #4

acoder
Expert Mod 15k+
P: 16,027
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
Jul 18 '08 #5

acoder
Expert Mod 15k+
P: 16,027
and i want to alert that object of name with this script

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  var form = document.forms[0];
  3. function showNameObject() {
  4.      alert(form.items[1][quantity].name);
  5. }
  6. </script>
  7.  
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.forms[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.
Jul 18 '08 #6

P: 77
If this is the error, that means the error is on the line before the function: var form=document.forms[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
Jul 23 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.