jquery global variables usable everywhere -
i starting doubt jquery easy use , flexible. have this:
var prodata=[]; var request = $.get("prodb.txt", function(data) { var lines=data.split(/\n/); var numberofmodels=lines.length-2; //var prodata=[]; var i; prodata.push(0); var fieldnames=lines[0].split(/\t/); (i = 1; < lines.length-1; ++i) { var fields=lines[i].split(/\t/); prodata.push(i); var j; prodata[i]={}; (j = 0; j < fields.length; ++j) { //prodata[i][fieldnames[j]]=fields[j]; var str=fieldnames[j]; prodata[i][str]=fields[j]; } } //fill dropdown list var options = ''; (i = 1; < lines.length-1; ++i) { if (prodata[i]['name'].indexof("elly") >= 0) { var iselected = i; } options += '<option label="bla" value="' + prodata[i]['id'] + '">' + prodata[i]['name']+', '+prodata[i]['brand']+', '+prodata[i]['model']+'</option>'; } $("#userchosenpromodel").html(options); //select default option $('#userchosenpromodel option[value="' + prodata[iselected]['id'] + '"]').attr("selected", "selected"); }, 'text'); //$.get
i use proid
, lower in code, after it's been defined that:
//submit form $('#submitbutton').click(function(e) { e.preventdefault(); request.done(function(){ proid=$('#userchosenpromodel option[selected="selected"]').val(); proid=parseint(proid); computeuserdimensions(prodata[proid]); }); }); console.log(proid);
how to?
same problem prodata
...i have request.done
can't rid of
thanks
you don't have problem jquery asynchronous/event based logic.
you can't synchronously use return of asynchronous function. must use result in callback or in function call callback :
request.done(function(){ var proid=$('#userchosenpromodel option[selected="selected"]').val(); console.log(proid); });
Comments
Post a Comment