[RESOLVED]Please help to built if condition

Hi All,

Please give me the logical if condition for below query:

first declared flag=0;

in first condition it becomes one as f=1;

in second condition it becomes f=2;

now i want to generate if condition when there is f value other then 0,1,or 2.

please tell me how to do this

i am using below if condition but its not working.

if ((flag == 0 && flag != 1 && flag != 2) || (flag == 0 && flag == 1 && flag != 2) || (flag == 0 && flag != 1 && flag == 2)) {}

please help me to fulfill if first condition is checked for false then second condition  is checked for false and if both to conditions are true then only execute 3 rd programming part which is to execute it both conditions are true only.

Regards,

Jayesh(From India,Mumbai)

Is this?

if (flag >= 0 && flag <= 2 ) {

.....

}

Hi jsiahaan,

<script type="text/javascript">

        var stringofchoice;
        var select;
        var completedata = "";
        var flag=0;

        function fetchdtls() {

          

            if( $('mytxt1').val().length < 0) {
                alert('Please enter text!');
                flag=1;
                return false;
                
            }

            if (document.getElementsByName('subCatId')[0].value == '-1')
            {
                alert('Please select category'); 
                flag=2;
                return false;
            }

           
            if (!flag >= 0 && !flag <= 2) {
                completedata = "";
                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice1 = "";
                select = document.getElementById("dd1");

                if ($('select[id$=dd1]').is(':visible')) {
                    stringofchoice1 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice1 = "";
                }
                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice2 = "";
                select = document.getElementById("dd2");
                if ($('select[id$=dd2]').is(':visible')) {
                    stringofchoice2 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice2 = "";
                }
                //completedata += (stringofchoice2);

                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice3 = "";
                select = document.getElementById("dd3");

                if ($('select[id$=dd3]').is(':visible')) {
                    stringofchoice3 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice3 = "";
                }
                // completedata += (stringofchoice3);

                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice4 = "";
                select = document.getElementById("dd4");
                if ($('select[id$=dd4]').is(':visible')) {
                    stringofchoice4 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice4 = "";
                }
                // completedata.concat(stringofchoice4);


                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice5 = "";
                select = document.getElementById("dd5");
                if ($('select[id$=dd5]').is(':visible')) {
                    stringofchoice5 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice5 = "";
                }
                //  completedata += (stringofchoice5);


                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice6 = "";
                select = document.getElementById("dd6");
                if ($('select[id$=dd6]').is(':visible')) {
                    stringofchoice6 = select.options[select.selectedIndex].text;
                    // completedata += (stringofchoice6);
                }
                else {
                    stringofchoice6 = "";
                }
                document.getElementById('<%=txtheadings.ClientID%>').value = "";


                stringofchoice7 = "";
                select = document.getElementById("dd7");

                if ($('select[id$=dd7]').is(':visible')) {
                    stringofchoice7 = select.options[select.selectedIndex].text;
                    // completedata.concat(stringofchoice7);
                }
                else {
                    stringofchoice7 = "";
                }
                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice8 = "";
                select = document.getElementById("dd8");

                if ($('select[id$=dd8]').is(':visible')) {
                    stringofchoice8 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice8 = "";
                }
                // completedata += (stringofchoice8);


                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice9 = "";
                select = document.getElementById("dd9");

                if ($('select[id$=dd9]').is(':visible')) {
                    stringofchoice9 = select.options[select.selectedIndex].text;
                    // completedata += (stringofchoice9);
                }
                else {
                    stringofchoice9 = "";
                }

                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice10 = "";
                select = document.getElementById("dd10");

                if ($('select[id$=dd10]').is(':visible')) {
                    stringofchoice10 = select.options[select.selectedIndex].text;
                }
                else {
                    stringofchoice10 = "";
                }
                //completedata.concat(stringofchoice10);

                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice11 = "";
                select = document.getElementById("dd11");
                if ($('select[id$=dd11]').is(':visible')) {
                    stringofchoice11 = select.options[select.selectedIndex].text;
                    // completedata += (stringofchoice11);
                }
                else {
                    stringofchoice11 = "";
                }
                document.getElementById('<%=txtheadings.ClientID%>').value = "";
                stringofchoice12 = "";
                select = document.getElementById("dd12");

                if ($('select[id$=dd12]').is(':visible')) {
                    stringofchoice12 = select.options[select.selectedIndex].text;
                    //completedata += (stringofchoice12);

                }
                else {
                    stringofchoice12 = "";
                }

                completedata = stringofchoice1 + '..' + stringofchoice2 + '..' + stringofchoice3 + '..' + stringofchoice4 + '..' + stringofchoice5 + '..' + stringofchoice6 + '..' + stringofchoice7 + '..' + stringofchoice8 + '..' + stringofchoice9 + '..' + stringofchoice10 + '..' + stringofchoice11 + '..' + stringofchoice12;
                document.getElementById('<%=txtheadings.ClientID%>').value = "";

                document.getElementById('<%=txtheadings.ClientID%>').value = completedata;




                // alert(completedata);
                completedata = '';

                return true;
            }

        
        }

    </script>

Thanks for reply but its not working .

Regards,

Jayesh(From India,Mumbai)

Hi,

Make sure that this script order is after jQuery.*.js.

Yes IT IS SIR,

please tell if 2 conditions are true i want to execute 3 rd part.

Regards,

Jayesh(From India,Mumbai)

Hi Jayesh.Dalvi,

It seems that you misunderstand the logic in your javascript function.

First, you define flag as 0 , in your first if condition, if the ( $(‘mytxt1′).val().length
< 0) is true

it will set the flag as 1 and  return false ,means the function is  close ,it will never execute the code below.

So if second if condition (document.getElementsByName(‘subCatId’)[0].value
== ‘-1′) is true ,it will set the flag as 2 ,and return false,and  also never execute the third if condition.

if all the two if conditions are false,then the code will step to the third if condition ,while the flag still is 0 ,you just need to check if it is ) like below:

if(flag==0){
///.
}

I suggest that you can set a breakpoint on the javascript,then press F12 to debug it .

Best Regards,

Kevin Shen.

if

Kevin Shen – MSFT

Hi Jayesh.Dalvi,
It seems that you misunderstand the logic in your javascript function.
First, you define flag as 0 , in your first if condition, if the ( $('mytxt1').val().length
< 0) is true
it will set the flag as 1 and  return false ,means the function is  close ,it will never execute the code below.
So if second if condition (document.getElementsByName('subCatId')[0].value
== '-1') is true ,it will set the flag as 2 ,and return false,and  also never execute the third if condition.
if all the two if conditions are false,then the code will step to the third if condition ,while the flag still is 0 ,you just need to check if it is ) like below:
if(flag==0){
///.
}

I suggest that you can set a breakpoint on the javascript,then press F12 to debug it .

Best Regards,

Kevin Shen.

if you dont know debug in browser, you can use "alert" function for check process javascript running

Hi 

jsiahaan,
Kevin Shen,
thanhphan467

Thanks for  reply to my post.

Your answers helped me to find right direction.

Last but not the least i will like to say is,

Kevin Sir is right,

I misunderstood the logic.

Now i solved it and its working fine.

Regards,

Jayesh(From India,Mumbai)

Leave a Reply