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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.