How do I put an Alert with IF in Javascript using Values List

Asked

Viewed 247 times

1

I’m setting up a javascript function that makes a list of values control SELECT in my SQL. Because the List of Both are giants. So maybe from the guy clicking directly to show everything from the table, I put a Alert in the value2, where the guy is required to enter the value. in the Filter he will bring what the guy wrote. and not the list of value by full.

Before logic was in only value 2 this condition, but now I need to put Alert also in value 1, but my if dies when I try to put the Alert to the value 1 like I did in 2.

function mostra_valores(c1)
{
  var ESTILO;  
  if(typeof c1.name==="undefined"){
   ESTILO=c1.previousSibling.name;
  } else {
   ESTILO=c1.name;
  }

  if(ESTILO=="P_PARAMETER_1"){ 
    DIV_LOV.style.display="inline";
    IFRAME.location = "PACKAGE1_PKG.VALOR?P_FILTRO="+document.PROCEDURE_VALOR.P_PARAMETER_1.value+"&P_TIPO=VALOR1";
     alert("Informe o valor 1");
  } else if(ESTILO=="P_PARAMETER_2"){
    if(document.PROCEDURE_VALOR.P_PARAMETER_2.value.length>2){
      DIV_LOV.style.display="inline";
      IFRAME.location = "PACKAGE1_PKG.VALOR?P_FILTRO="+document.PROCEDURE_VALOR.P_PARAMETER_2.value+"&P_TIPO=VALOR2";
    } else {
      alert("Informe o valor 2"); 
    }
  }
  IFRAME.focus();      
}

would need the alert("informe o valor 1"); equals the condition of alert ("informe o valor 2");

1 answer

2


The way I see it, you could use two if...else separated and when entering one of the else's, exit function with return;:

if(ESTILO=="P_PARAMETER_1"){ 
   DIV_LOV.style.display="inline";
   IFRAME.location = "PACKAGE1_PKG.VALOR?P_FILTRO="+document.PROCEDURE_VALOR.P_PARAMETER_1.value+"&P_TIPO=VALOR1";
}else{
   alert("Informe o valor 1");
   return;
}

if(ESTILO=="P_PARAMETER_2" && document.PROCEDURE_VALOR.P_PARAMETER_2.value.length>2){
   DIV_LOV.style.display="inline";
   IFRAME.location = "PACKAGE1_PKG.VALOR?P_FILTRO="+document.PROCEDURE_VALOR.P_PARAMETER_2.value+"&P_TIPO=VALOR2";
} else {
   alert("Informe o valor 2"); 
   return;
}

If the first if is not satisfied, will not reach the second. And if the first if is satisfied and the second not, will not execute the IFRAME.focus();.

In the second if you can put the two conditions in the same if, without having to do one inside the other.

  • 1

    Our easier than I thought, it worked so, I think I was wanting to decorate too much in the IF. thanks a lot friend

Browser other questions tagged

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