function save()
{
//int count=0;
var txt1 = document.getElementById('txtEmpFName').value; // textbox 1 ID is txt1
var txt2 = document.getElementById('txtEmpmiName').value;
var txt3 = document.getElementById('txtEmpDtofInterview').value;
var txt4 = document.getElementById('txtEmpDtofJoining').value;
if (txt1 == "0")
{
count = count + 1;
alert("plz fill the employe's First name!!");
return true;
}
if (txt2 == "0") {
count = count + 1;
alert("plz fill the employe's middle name!!");
return true;
}
if(txt3 =="0")
{
count = count + 1;
alert("plz fill the employe's Date Of interview name!!");
return true;
}
if(txt4=="0")
{
count = count + 1;
alert("plz fill the employe's Date of joini name!!");
return true;
}
if (confirm('Do You Want to Add Record') == true)
return true;
else
return false;
}
<asp:Button ID="btnadd" runat="server" class="btn save" Text="New"
onclick="btnadd_Click" OnClientClick="save();" style="height: 26px" />
i use this code also
<asp:Button ID="btnadd" runat="server" class="btn save" Text="New"
onclick="btnadd_Click" OnClientClick=" return save();" style="height: 26px" />
it not calling function .........
pls help meeeeeeeeeee
In my site javascript function is not calling ?
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sunny SharmaRank #223 · 11.1K pointsPosted May 24, 2013, 9:59 PM EDT
Firstly I see there's problem in your Java Script function. Properties and methods are not teh same in java script as in C#.
"txtSelectDate.Text.Trim().Length <= 0" This code will not run.
Your JavaScript code should be like this:
var txtBox = document.getElementById('txtSelectDate');
if(txtBox.value.length<=0) { ... }
OR
if you've included jQuery in your page then you can do it like:
if($('#txtSelectDate').value.length<=0) {...}
Please don't forget to accept this as answer if it helps!
Thanks.
krishna angirekula49 pointsPosted May 24, 2013, 10:19 PM EDT
Sunny SharmaRank #223 · 11.1K pointsPosted May 24, 2013, 10:21 PM EDT
Sunny SharmaRank #223 · 11.1K pointsPosted May 24, 2013, 10:36 PM EDT
Later in your code I found that the problem lies only with your logic.
I've created a sample HTML page to demonstrate how to use Java Script functions. This will give you the whole idea. What you're currently doing is completely opposite to what you should.
You're returning true when you should not. Returning a true causes the page to proceed further while returning a false causes it to stop any further processing. See the demo in attached file.
Hope it helps!
Thanks.