i have these two jquery functions and one of them is not getting called.but when i comment one of them the other one gets called and vice-versa.
1st
$(function() {
$("[id*=tvAi1] input[type=checkbox]").bind("click",
function() {
var table = $(this).closest("table");
if (table.next().length > 0 && table.next()[0].tagName == "DIV") {
//Is Parent CheckBox
var childDiv = table.next();
var isChecked = $(this).is(":checked");
if (isChecked) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the MobileBankingService.");
this.checked = false;
$('#CellNumberTextBox').focus();
return false;
}
}
$("input[type=radio]", childDiv).each(function() {
if (isChecked) {
$(this).attr("checked", "checked");
return false;
} else {
$(this).removeAttr("checked");
}
});
}
});
$("#SaveButton").bind("click",
function (e) {
$("#hdMobile").val("");
var tv = document.getElementById("<%= tvAi1.ClientID %>");
var chkArray = tv.getElementsByTagName("input");
for (i = 0; i <= chkArray.length - 1; i++) {
if (i == 0) {
$.ajax({
type: "POST",
url: "AddNewCustomer.aspx/SetSession",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
}
});
}
if (chkArray[i].type == 'radio') {
if (chkArray[i].checked == true) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the MobileBankingService.");
$('#CellNumberTextBox').focus();
$.hideprogress();
return false;
}
if ($("#hdMobile").val() == "" || $("#hdMobile").val() == null) {
$("#hdMobile").val(chkArray[i].value);
} else {
$("#hdMobile").val($("#hdMobile").val() + "," + chkArray[i].value);
}
}
}
}
});
});
2nd one
$(function() {
$("[id*=tvAi] input[type=checkbox]").bind("click",
function() {
var table = $(this).closest("table");
if (table.next().length > 0 && table.next()[0].tagName == "DIV") {
//Is Parent CheckBox
var childDiv = table.next();
var isChecked = $(this).is(":checked");
if (isChecked) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the SMSService.");
this.checked = false;
$('#CellNumberTextBox').focus();
return false;
}
}
$("input[type=radio]", childDiv).each(function() {
if (isChecked) {
$(this).attr("checked", "checked");
return false;
} else {
$(this).removeAttr("checked");
}
});
}
});
$("[id*=tvAi] input[type=radio]").bind("click",
function() {
//hdSms
var parentDIV = $(this).closest("DIV");
if ($(this).is(":checked")) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert("Please enter the Cell Number because you have asked for the SMSService.");
this.checked = false;
$('#CellNumberTextBox').focus();
return false;
}
$("input[type=checkbox]", parentDIV.prev()).attr("checked", "checked");
} else {
$("input[type=checkbox]", parentDIV.prev()).removeAttr("checked");
}
});
$("#SaveButton").bind("click",
function(e) {
$("#hdSms").val("");
var tv = document.getElementById("<%= tvAi.ClientID %>");
var chkArray = tv.getElementsByTagName("input");
for (i = 0; i <= chkArray.length - 1; i++) {
if (i == 0) {
$.ajax({
type: "POST",
url: "AddNewCustomer.aspx/SetSession",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
}
});
}
if (chkArray[i].type == 'radio') {
if (chkArray[i].checked == true) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the SMSService.");
$('#CellNumberTextBox').focus();
$.hideprogress();
return false;
}
if ($("#hdSms").val() == "" || $("#hdSms").val() == null) {
$("#hdSms").val(chkArray[i].value);
} else {
$("#hdSms").val($("#hdSms").val() + "," + chkArray[i].value);
}
}
}
}
});
});
I tried combining them both but didnt helped.I want both of them to be called according to div enabled/disabled from my code-behind.Newbie here.Help Appreciated.
i have these two jquery functions and one of them is not getting called.but when i comment one of them the other one gets called and vice-versa.
Which one not be called? the second one?
From your description and code, I think that the reason for your problem is that the second jquery function will has error after the first jquery function executed firstly.
So I suggest you could debug second jquery function. You could use F12 developer tools to check this
Note: if you still have problem about this, would you please post your complete code so I could reproduce your problem.
Best regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Can you look into this sir?if i comment the first one the second one gets executed and if i comment the second one first one gets executed.when i use both of them only the first one gets executed.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Sir that user control is not related to my problem sir.and about debugging.i cant reach to my second function i tried using debugger and console.log.like i said if i comment the first function the second function works but not when both of them are uncommented.
Member
34 Points
158 Posts
Jquery function not working with multiple function after DOM load
Aug 29, 2017 05:39 PM|tarun02|LINK
i have these two jquery functions and one of them is not getting called.but when i comment one of them the other one gets called and vice-versa.
1st
2nd one
I tried combining them both but didnt helped.I want both of them to be called according to div enabled/disabled from my code-behind.Newbie here.Help Appreciated.
Star
8670 Points
2882 Posts
Re: Jquery function not working with multiple function after DOM load
Aug 30, 2017 03:16 AM|Cathy Zou|LINK
Hi tarrun02
As far as i know, we could have multiple $(document).ready() or $(function(){}) calls in a page.
http://www.learningjquery.com/2006/09/multiple-document-ready
https://stackoverflow.com/questions/17487825/document-ready-twice-on-same-page-which-will-execute-first
Which one not be called? the second one?
From your description and code, I think that the reason for your problem is that the second jquery function will has error after the first jquery function executed firstly.
So I suggest you could debug second jquery function. You could use F12 developer tools to check this
Note: if you still have problem about this, would you please post your complete code so I could reproduce your problem.
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
34 Points
158 Posts
Re: Jquery function not working with multiple function after DOM load
Aug 30, 2017 06:36 AM|tarun02|LINK
hello sir..here is my complete code
Can you look into this sir?if i comment the first one the second one gets executed and if i comment the second one first one gets executed.when i use both of them only the first one gets executed.
Star
8670 Points
2882 Posts
Re: Jquery function not working with multiple function after DOM load
Aug 30, 2017 07:20 AM|Cathy Zou|LINK
Hi tarun02,
For you used usercontrol, so it is hard for me to reproduce your problem,
As I mentioned in first reply.
The second jquery function will has error after the first jquery function executed firstly.
So I suggest you could debug second jquery function. You could use F12 developer tools to check this
For how to debug js code, please read the articles below.
https://www.w3schools.com/js/js_debugging.asp
https://msdn.microsoft.com/en-us/library/dn255007(v=vs.85).aspx
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
34 Points
158 Posts
Re: Jquery function not working with multiple function after DOM load
Aug 30, 2017 07:37 AM|tarun02|LINK
Sir that user control is not related to my problem sir.and about debugging.i cant reach to my second function i tried using debugger and console.log.like i said if i comment the first function the second function works but not when both of them are uncommented.
Thanks