0

I am trying to call 2 javascript one time on client click event. I am only able to call them one of the javascript. Once the user clicks the button, i want to call 2 javascript because each javascript is checking 2 diferent gridviews. How can i call both of them one time on client click event. Here is my button

 <asp:LinkButton ID="btn_Submit" runat="server" CssClass="btn btn-primary" OnClientClick="return validate_1();" OnClick="btn_Submit_Click"> 
     <i aria-hidden="true" class="glyphicon glyphicon-ok"></i>Submit
     </asp:LinkButton>

here is the 1st one:

<script type="text/javascript">
        function validate_1() {
            var flag = true;
            var dropdowns = new Array(); //Create array to hold all the dropdown lists.
            var gridview = document.getElementById('<%=Main_GV.ClientID%>'); //GridView1 is the id of ur gridview.
            dropdowns = gridview.getElementsByTagName('Select'); //Get all dropdown lists contained in GridView1.
            for (var i = 0; i < dropdowns.length; i++) {
                if (dropdowns.item(i).value == 'Select') //If dropdown has no selected value
                {
                    flag = false;
                    break; //break the loop as there is no need to check further.
                }
            }
            if (!flag) {
                alert('Warning.....  Thanks');
                document.getElementById('<%=btn_Submit.ClientID%>').style.visibility = 'hidden';
            }
            return flag;         

        }
    </script>

here is the 2nd one

<script type="text/javascript">

        function validate_2() {

            var f = document.getElementById('<%=GV_Test.ClientID%>');
            for (var i = 0; i < f.getElementsByTagName("input").length ; i++) {
                if (f.getElementsByTagName("input").item(i).type == "text") {

                    if (f.getElementsByTagName("input").item(i).value == 0) {
                        alert("warning....");
                        f.getElementsByTagName("input").item(i).focus();
                        return false;
                    }

                }

            }
        }
    </script>

i want to call both validate_1() and validate_2(). Thanks

1
  • Why dont you call fuction call inside a fuction.That means function validate_1() { //your stuff ; validate_2()} Commented Feb 15, 2015 at 5:13

1 Answer 1

1

how about :

return OnClientClick="return validate_1() && validate_2();"

If validate_1 doesn't pass then validate_2 will not get called. So if both functions return truthy, then your postback will take place.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.