Skip to content

In my site javascript function is not calling ?

krishna angirekula

krishna angirekula

Asked May 24, 2013, 8:25 PM EDT4 answers
Share
LinkedInX
   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

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi Krishna,

    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.
    0
  • krishna angirekula
    0
    i change but function is not call
    0
  • Sunny  Sharma
    0
    please share the complete code/project... would be much easier to track down the error. may be the problem lies behind the logic.
    0
  • Sunny  Sharma
    0
    Hi krishna,
    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.        
    0