Skip to content

Instantly share code, notes, and snippets.

@cluelesscoder
Created July 8, 2012 20:41
Show Gist options
  • Save cluelesscoder/3072712 to your computer and use it in GitHub Desktop.
Save cluelesscoder/3072712 to your computer and use it in GitHub Desktop.
loading many-to-many divs
function loadStockDivs() {
$.getJSON(
"test.php",
"process=loadstocks",
function(data) {
data.counter = 0;
$.each(data.stocks, function(i,stock) {
if (i != 0) {
counter = i;
counterminus = counter-1;
currentid = data.stocks[counter].stock_id;
previousid = data.stocks[counterminus].stock_id;
if (previousid == currentid) {
var extraSector = '<span id=stock'+stock.stock_id+'&sector'
+stock.sector_id+'style="float:right">Sector: '+data.stocks[i].sector_name+'</span>';
//selector = 'stock'+stock.stock_id+'\\&'+stock.sector_id;
//$(selector).append(extraSector);
//"#stock"+stock.stock_id+"\\&sector"+stock.sector_id+""
//sectorid = stock.sector_id;
//$(extraSector).insertAfter('select[id="'+selector+'"]');
$(extraSector).insertAfter('stock'+stock.stock_id+'\\&sector'+stock.sector_id);
return true;
/*'select[id="stock'+stock.stock_id+'&sector'+stock.sector_id+'"]'*/
}
}
var newDiv =
'<div id="'+stock.stock_id+'" class="indiv_record"> \
<span style="font:bold; border-width:0.5px; \
padding:1px; border-style: solid;">'
+stock.stock_name+'</span> \
<span id="stock'+stock.stock_id+'&sector'+stock.sector_id+'" style="float:right">Sector: '+stock.sector_name+'</span> \
<br>'+stock.stock_ticker+'<br> \
<textarea>'+stock.stock_desc+'</textarea> \
<input type="button" value="Delete this record" \
class="delete" style="float:right" /></div>'
//$(newDiv).appendTo("#content");
//'<div id="'+stock.stock_id+'" class="indiv_record"></div>'
$("#content").append(newDiv);
//alert(stock.stock_name.toString());
//alert(data.toSource());
//alert(JSON.stringify(stock));1 `
//alert(data.counter);
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment