Why not jquery working in Asp.net [Resolved]

Posted by Cpatil1000 under ASP.NET on 8/12/2016 | Points: 10 | Views : 261 | Status : [Member] | Replies : 2
hi,
I am trying to validate for asp.net control. it is accepted first validition and remaining
is bot doing validation. only checking tbNextCallDate and remaining is not checking. I am
using bootstrap modal. I am getting 'Do you want Continue' double message.
<script type="text/javascript">
$(document).ready(function () {
$('#<%=bSaveHistory.ClientID%>').on('click', function (e) {
var flag = true;

var selectEngMar = $("#<%= rblLanguage.ClientID %> input:checked").val();

if ($('#<%=ddlHistoryStatus.ClientID%>').val() != "4" && $('#<%=ddlHistoryStage.ClientID%>').val() != "9") {
if ($('#<%=tbNextCallDate.ClientID%>').val() == "") {
alert('Please Enter Next Call Date');
$('#<%=tbNextCallDate.ClientID%>').focus();
flag = false;
}
}
else if ($('#<%=ddlHistoryStatus.ClientID%>').val() == "0") {
alert('Please Select Status');
$('#<%=ddlHistoryStatus.ClientID%>').focus();
flag = false;
}
else if ($('#<%=ddlHistoryStage.ClientID%>').val() == "0") {
alert('Please Select Stage');
$('#<%=ddlHistoryStage.ClientID%>').focus();
flag = false;
}
else if (!isNaN(selectEngMar)) {
if (selectEngMar == 0) {
if ($('#<%=tbCommentEng.ClientID%>').val() == "") {
alert("Please Enter English Comment");
$('#<%=tbCommentEng.ClientID%>').focus();
flag = false;
}
}
else if (selectEngMar == 1) {
if ($('#<%=tbCommentMar.ClientID%>').val() == "") {
alert("Please Enter Marathi Comment");
$('#<%=tbCommentMar.ClientID%>').focus();
flag = false;
}
}
}

if (flag == false) {
e.preventDefault();
return false;
}
else if (flag == true) {
if (confirm("Do you want Continue..?") == true) {
return true;
}
else {
return false;
}
}
});
});
</script>


please find herewith attachment..




Responses

Posted by: A2H on: 8/14/2016 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
You can try with the below code. The problem is once your first if condition is succeeded then remaining elseif conditions wont work. To resolve the issue you need to move the validation code inside the if block

<script type="text/javascript">
$(document).ready(function () {
$('#<%=bSaveHistory.ClientID%>').on('click', function (e) {
debugger;
var flag = true;
var selectEngMar = $("#<%= RadioButtonList1.ClientID %> input:checked").val();
if ($('#<%=ddlHistoryStatus.ClientID%>').val() != "4" && $('#<%=ddlHistoryStage.ClientID%>').val() != "9") {
if ($('#<%=tbNextCallDate.ClientID%>').val() == "") {
alert('Please Enter Next Call Date');
$('#<%=tbNextCallDate.ClientID%>').focus();
flag = false;
}
else if ($('#<%=ddlHistoryStatus.ClientID%>').val() == "0") {
alert('Please Select Status');
$('#<%=ddlHistoryStatus.ClientID%>').focus();
flag = false;
}
else if ($('#<%=ddlHistoryStage.ClientID%>').val() == "0") {
alert('Please Select Stage');
$('#<%=ddlHistoryStage.ClientID%>').focus();
flag = false;
}
else if (!isNaN(selectEngMar)) {
if (selectEngMar == 0) {
if ($('#<%=tbCommentEng.ClientID%>').val() == "") {
alert("Please Enter English Comment");
$('#<%=tbCommentEng.ClientID%>').focus();
flag = false;
}
}
else if (selectEngMar == 1) {
if ($('#<%=tbCommentMar.ClientID%>').val() == "") {
alert("Please Enter Marathi Comment");
$('#<%=tbCommentMar.ClientID%>').focus();
flag = false;
}
}
}
}
else if ($('#<%=ddlHistoryStatus.ClientID%>').val() == "0") {
alert('Please Select Status');
$('#<%=ddlHistoryStatus.ClientID%>').focus();
flag = false;
}
else if ($('#<%=ddlHistoryStage.ClientID%>').val() == "0") {
alert('Please Select Stage');
$('#<%=ddlHistoryStage.ClientID%>').focus();
flag = false;
}
else if (!isNaN(selectEngMar)) {
if (selectEngMar == 0) {
if ($('#<%=tbCommentEng.ClientID%>').val() == "") {
alert("Please Enter English Comment");
$('#<%=tbCommentEng.ClientID%>').focus();
flag = false;
}
}
else if (selectEngMar == 1) {
if ($('#<%=tbCommentMar.ClientID%>').val() == "") {
alert("Please Enter Marathi Comment");
$('#<%=tbCommentMar.ClientID%>').focus();
flag = false;
}
}
}

if (flag == false) {
e.preventDefault();
return false;
}
else if (flag == true) {
if (confirm("Do you want Continue..?") == true) {
return true;
}
else {
return false;
}
}
});
});
</script>


Thanks,
A2H
My Blog

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhuvanesh6 on: 8/18/2016 [Member] Starter | Points: 25

Up
0
Down
You have missed checking the other conditional checks in the first "if" part statement,

  if ($('#<%=ddlHistoryStatus.ClientID%>').val() != "4" && $('#<%=ddlHistoryStage.ClientID%>').val() != "9") {


When this condition is not satisfied other part statement can be checked, which was missed.


Bhuvan

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response