Jump to content

if statement not working


etsted

Recommended Posts

when i console.log the str variable it says "No suggestions", but when i try to use that statement in a if statement it doesnt work.

var suggested_titels = ajax.responseText.split("S_E_C_R_E_T__S_I_G_N__!_|_!_|");                              for(var i =0;i < suggested_titels.length; i++){                           var space = document.createElement("BR");              var node = document.createElement("SPAN");              var textnode=document.createTextNode(suggested_titels[i]);              var check = document.createTextNode(suggested_titels[0]);              var str = document.createElement("DIV");              str.appendChild(check);              node.appendChild(textnode);             node.appendChild(space);              sQ.appendChild(node);              if(suggested_titels[0] == "No suggestions"){                  sQ.innerHTML = "";              }          }            console.log(str);

sQ is supposed to get empty when there is not suggestions in the DB

Link to comment
Share on other sites

So IF ajax return with only "No suggestions" which when split its index will be suggested_titels[0] you want sQ whatever that is? to be empty? but still create br, span and the rest

          for(var i =0;i < suggested_titels.length; i++){ //length will be 1 which will equal "No suggestions"                           var space = document.createElement("BR"); //still create br              var node = document.createElement("SPAN"); // still create span              var textnode=document.createTextNode(suggested_titels[i]); //still create text node of "No suggestions" as this will be the only text returned              var check = document.createTextNode(suggested_titels[0]); // still ditto              var str = document.createElement("DIV"); //still create div              str.appendChild(check); // still append to div - check -> "No suggestions"              node.appendChild(textnode); //still append to span - textnode ->  "No suggestions"             node.appendChild(space); //still append to span - space -> "<br>"              sQ.appendChild(node); //still append to sQ? - span with textnode ->  "No suggestions" + "<br>"              if(suggested_titels[0] == "No suggestions"){ // if suggested_titels[0] matches "No suggestions"                  sQ.innerHTML = ""; // sQ whatever that is will be cleared.              }          }

IS this right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...