I am using jquery in my asp.net website. It was working fine in my local system. But when I published it in the server it is not working. My jquery code is as follow,
$("#<%=btnSubmit.ClientID %>").click(function (ev) {
ev.preventDefault();
$(this).attr("disabled", true);
if ($("#<%=ddlLetterType.ClientID %>").val() == "-1") {
alert("Please select a letter.");
$("#<%=ddlLetterType.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=ddlLetterType.ClientID %>").val() == "1") {
if ($("#<%=ddlEmbassyCountry.ClientID %>").val() == "-1") {
alert("Please select an Embassy Country.");
$("#<%=ddlEmbassyCountry.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=ddlTravelCountry.ClientID %>").val() == "-1") {
alert("Please select a Travel Country.");
$("#<%=ddlTravelCountry.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=txtEmbassyAddress.ClientID %>").val() == "") {
alert("Please enter embassy address.");
$("#<%=txtEmbassyAddress.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=txtPassportNo.ClientID %>").val() == "") {
alert("Please enter passport no.");
$("#<%=txtPassportNo.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=txtPlaceOfMeeting.ClientID %>").val() == "") {
alert("Please enter place of meeting.");
$("#<%=txtPlaceOfMeeting.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=txtStartDate.ClientID %>").val() == "") {
alert("Please enter start date.");
$("#<%=txtStartDate.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else if ($("#<%=txtEndDate.ClientID %>").val() == "") {
alert("Please enter end date.");
$("#<%=txtEndDate.ClientID %>").focus();
$("#<%=btnSubmit.ClientID %>").attr("disabled", false);
return false;
} else {
var parameter = {
request_no: $("#<%=lblRequestNo.ClientID %>").text(),
initiator_user_id: $("#<%=hInitiatorUserId.ClientID %>").val(),
initiatingDate: $("#<%=lblRequestdate.ClientID %>").text(),
embassy_country_id: $("#<%=ddlEmbassyCountry.ClientID %>").val(),
embassy_address: $("#<%=txtEmbassyAddress.ClientID %>").val(),
nationality: $("#<%=lblNationality.ClientID %>").text(),
passport_no: $("#<%=txtPassportNo.ClientID %>").val(),
company: $("#<%=lblCompanyName.ClientID %>").text(),
designation: $("#<%=lblDesignation.ClientID %>").text(),
joining_date: $("#<%=lblJoiningDate.ClientID %>").text(),
travel_country_id: $("#<%=ddlTravelCountry.ClientID %>").val(),
place_of_meeting: $("#<%=txtPlaceOfMeeting.ClientID %>").val(),
travel_start_date: $("#<%=txtStartDate.ClientID %>").val(),
travel_end_date: $("#<%=txtEndDate.ClientID %>").val(),
letter_filename: $("#<%=lblRequestNo.ClientID %>").text() + "_business_letter",
status: '2',
hr_letter_type_id: $("#<%=ddlLetterType.ClientID %>").val()
};
$.ajax({
type: "POST",
url: "<%=ResolveUrl("~/HRLetterService.asmx") %>/RegisterHRLetterBusinessData",
data: JSON.stringify(parameter),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
__doPostBack('<%=btnSubmit.ClientID.Replace("_", "$") %>', '');
},
error: function (msg) {
alert("Error in saving the request. Please contact your administrator by sending the screen shot to unify.admin@unilever.com");
$(this).attr("disabled", false);
return false;
}
});
}
}
.
.
.
.
I haven’t posted all the code as the code is fine and there is no error as such. But the only problem is at if statements. The if and else if statements get executed but the else part doesn’t get executed. What can be the problem? Could you please help me? Thanks in Advance.
Your code is not wrapped in
readyevent callback. If your code is placed in head as is, it will fire before the html exists and will never bind to the elements it is looking for, since they aren’t there yet.If this doesn’t resolve issue, use a browser console to check for errors thrown