javascript - What is the value of a blank line in a textarea? -
i'm writing function check value of each line in textarea , output results in textarea.
my problem don't know value of blank line in text area, i've tried "", /\w/, undefined, , null, , none of seem work. have right now:
function check(){ var textareavalue= $("textarea#mincheck").val(); var valuearray= $("textarea#mincheck").val().split("\n"); var parsedarray=[]; for(i=0; i<valuearray.length;i++){ if(valuearray[i]==/\w/){ parsedarray.push(valuearray[i] + "|blank"); }else if(valuearray[i]>=0 && valuearray[i]<=999){ parsedarray.push(valuearray[i] + "|" + "brand1"); }else if(valuearray[i]>=1000 && valuearray[i]<=1999){ parsedarray.push(valuearray[i] + "|" + "brand2"); }else if(valuearray[i]>=2000 && valuearray[i]<=2999){ parsedarray.push(valuearray[i] + "|" + "brand3"); }else if(valuearray[i]>=3000 && valuearray[i]<=3999){ parsedarray.push(valuearray[i] + "|" + "brand4"); }else{ parsedarray.push(valuearray[i]+"|invalid"); } } $("textarea#minparsed").val(parsedarray.join("\n")); }
for now, gives me "|brand1" when blank line checked.
try : trim value of line , check empty space if(valuearray[i].trim()==""){
, see below code
function check(){ var textareavalue= $("textarea#mincheck").val(); var valuearray= $("textarea#mincheck").val().split("\n"); var parsedarray=[]; for(i=0; i<valuearray.length;i++){ if(valuearray[i].trim()==""){ parsedarray.push(valuearray[i] + "|blank"); }else if(valuearray[i]>=0 && valuearray[i]<=999){ parsedarray.push(valuearray[i] + "|" + "brand1"); }else if(valuearray[i]>=1000 && valuearray[i]<=1999){ parsedarray.push(valuearray[i] + "|" + "brand2"); }else if(valuearray[i]>=2000 && valuearray[i]<=2999){ parsedarray.push(valuearray[i] + "|" + "brand3"); }else if(valuearray[i]>=3000 && valuearray[i]<=3999){ parsedarray.push(valuearray[i] + "|" + "brand4"); }else{ parsedarray.push(valuearray[i]+"|invalid"); } } $("textarea#minparsed").val(parsedarray.join("\n")); }
Comments
Post a Comment