Javascript comparison this jumping straight

Asked

Viewed 39 times

0

I’m making a registration page with 5 dropdowns on each line, but the user will not be required to complete all dropdowns to complete the registration, for example, if the user fills the entire first line of registration, automatically the second line will be available so that if he wants he can fill in too, but if he does not fill it he can send only the contents of the first line to the bank, as I can check if the second line has also been filled in at javascript?

I tried that way:

if ($data.formInput.codEmpresaOTRS01.codigoEmpresa.length > 1 && $data.formInput.codEmpresaOTRS02.codigoEmpresa.length > 1){
    //Quando tanto a segunda linha quanto a primeira for preenchida
    x = 2;
} else if ($data.formInput.codEmpresaOTRS01.codigoEmpresa.length > 1){
   //Quando a primeira for preenchida apenas
   x = 1;
}
return x;

But it does not enter the second condition, which may be wrong in these comparisons?

  • It was not very clear how you are organized your html, could you post the form code in the question? Another thing, it’s only 2 lines of registration at most?

  • It’s not just two lines but I believe that when I can make it work for two lines just replicate to the other lines. And the HTML code I do not have access because I use a tool where I drag the items to the screen and it itself generates the page designer, I can only put code (javascript, json, etc) to run behind, my problem by what I noticed is that this variable $data.formInput.codEmpresaOTRS01.codigoEmpresa comes blank, but is not null in case, simply contains nothing

  • Ah a way to check if the variable is empty in javascript @Pedrosouza

  • 'Cause if I put return $$data.formInput.codEmpresaOTRS01.codigoEmpresa and call it on my development screen, while I do not select anything in the dropdown I assign this variable is not displayed anything

  • If this variable is global, and you have access to the developer console (for example, Google Chrome), you can directly use the console.log($data.formInput.codEmpresaOTRS01.codigoEmpresa) and see what returns. You can also use this command in your code and see at runtime what is printed on the console.

1 answer

0


I figured out what I needed from that question, it is not that my variable was blank or null and yes it is that it had not been defined yet

Browser other questions tagged

You are not signed in. Login or sign up in order to post.