Hey everyone sorry to post again regarding a piece of code I am working with it seems that I consistently getting the wrong item in an array of data.
Any help is appreciated and sorry to post such a large block of code:
[code]
<script>
function inItems( prop, selObj, OrdersItemsList ) {
var id = Number( selObj.options[selObj.selectedIndex].value );
var i = 0;
var end = OrdersItemsList.length;
for( i = 0; i < end; i++ ) { alert( “LOOKING AT: ” + OrdersItemsList[i][‘id’] + ” – ” + OrdersItemsList[i][‘ordernum’] );
if( OrdersItemsList[i][‘ordernum’] == id ) { alert( “CALLING: ” + id + ” FROM: ” + OrdersItemsList[i][‘ordernum’] );
SetItems( OrdersItemsList[i][‘id’] );
continue;
}
}
}
row_no = 1;
function SetItems( selObj )
{
var id = selObj;
var textbox_quantity = document.createElement( ‘input’ );
var textbox_description = document.createElement( ‘textarea’ );
var textbox_price = document.createElement( ‘input’ );
var textbox_part = document.createElement( ‘input’ );
var textbox_source = document.createElement( ‘textarea’ );
textbox_quantity.setAttribute( ‘type’, ‘text’ );
textbox_quantity.setAttribute( ‘name’, ‘add_order_items[‘ + row_no + ‘][]’ );
textbox_quantity.setAttribute( ‘value’, OrdersItemsList[id][‘quantity’] );
textbox_quantity.setAttribute( ‘size’, ‘4’ );
textbox_description.setAttribute( ‘cols’, ’20’ );
textbox_description.setAttribute( ‘rows’, ‘2’ );
textbox_description.setAttribute( ‘name’, ‘add_order_items[‘ + row_no + ‘][]’ );
textbox_description.value = OrdersItemsList[id][‘description’];
textbox_price.setAttribute( ‘type’, ‘text’ );
textbox_price.setAttribute( ‘name’, ‘add_order_items[‘ + row_no + ‘][]’ );
textbox_price.setAttribute( ‘value’, OrdersItemsList[id][‘price’] );
textbox_price.setAttribute( ‘size’, ’15’ );
textbox_part.setAttribute( ‘type’, ‘text’ );
textbox_part.setAttribute( ‘name’, ‘add_order_items[‘ + row_no + ‘][]’ );
textbox_part.setAttribute( ‘value’, OrdersItemsList[id][‘partnum’] );
textbox_part.setAttribute( ‘size’, ’15’ );
textbox_source.setAttribute( ‘cols’, ’20’ );
textbox_source.setAttribute( ‘rows’, ‘2’ );
textbox_source.setAttribute( ‘name’, ‘add_order_items[‘ + row_no + ‘][]’ );
textbox_source.value = OrdersItemsList[id][‘source’];
var remove = ”;
var msg = ”;
var tbl = document.getElementById( ‘itemtable’ );
var rowIndex = document.getElementById( ‘itemrow’ ).value;
try {
var newRow = tbl.insertRow( row_no );
var newCell = newRow.insertCell( 0 );
newCell.innerHTML = remove;
var newCell = newRow.insertCell( 1 );
newCell.appendChild( textbox_quantity );
var newCell = newRow.insertCell( 2 );<table id=”itemtable” width=”100%”><tr id=”itemrow”></tr></table>
newCell.appendChild( textbox_description );
var newCell = newRow.insertCell( 3 );
newCell.appendChild( textbox_price );
var newCell = newRow.insertCell( 4 );
newCell.appendChild( textbox_part );
var newCell = newRow.insertCell( 5 );
newCell.appendChild( textbox_source );
var newCell = newRow.insertCell( 6 );
newCell.innerHTML = msg;
row_no++;
} catch ( ex ) {
alert( ex );
}
}
var OrdersItemsList = [
{‘id’:’1′,’ordernum’:’1′,’quantity’:’2′,’description’:’Item 1′,’price’:’1.99′,’partnum’:’partnumber002′,’source’:’testing this application’},
{‘id’:’2′,’ordernum’:’1′,’quantity’:’3′,’description’:’item 2′,’price’:’2.99′,’partnum’:’partnumber003′,’source’:”},
{‘id’:’3′,’ordernum’:’3′,’quantity’:’2′,’description’:’This is numero dos’,’price’:’1.99′,’partnum’:’xyz987′,’source’:’testing again’},
{‘id’:’4′,’ordernum’:’4′,’quantity’:’2′,’description’:’testing o’,’price’:’13.23′,’partnum’:’2′,’source’:’this is a test’},
{‘id’:’5′,’ordernum’:’4′,’quantity’:’6′,’description’:’item 2′,’price’:’2.99′,’partnum’:’partnumber003′,’source’:’another t4es’},
]
</script>
<b>Select order to edit:</b> <select name=”edit_order_orders” id=”edit_order_orders” onchange=”javascript:inItems( ‘1’, this, OrdersItemsList )”><option name=”——————————” value=”——————————“>——————————</option><option name=”1″ value=”1″>02/28/2008 : Joes computer crap</option><option name=”2″ value=”3″>03/05/2008 : WHODUNNIT</option><option name=”3″ value=”4″>03/11/2008 : whoisyoupunk*****</option></select>
<table id=”itemtable” width=”100%”><tr id=”itemrow”></tr></table>