0

i was comparing from date and to date in java script if the value is false i am returning false but the program is executing.

my java script code

function Noofdays() {

        var total= document.getElementById('ctl00_MainContent_Txtabc');
            var days = document.getElementById('ctl00_MainContent_ddldays');

            if (total= days) {
                alert("same");
                return true;
            }
            else {
                alert("not same");
                return false;
            }   
        }

i was calling this function from c# code in save button,

ScriptManager.RegisterStartupScript(this, GetType(), "FromDateSample", "Noofdays();", true);

and i had a on client click event in save button.

1
  • = is assignment, == or === is comparison Commented Jan 25, 2014 at 7:30

3 Answers 3

1

The condition of your if-statement is assigning the value of days to total. To compare the two values, you need to use a comparison operator (== or ===).

Sign up to request clarification or add additional context in comments.

2 Comments

i did it but my programe still executes when the condition is false
i had given return false but it was not working,how can i do that ??
1
  1. = is assignment, == or === is comparison
  2. You need to tack a .value on to your fields
  3. You may want to convert to numbers

    var total= +document.getElementById('ctl00_MainContent_Txtabc').value;
    var days = +document.getElementById('ctl00_MainContent_ddldays').value;
    if (total==days) {
    

Comments

0

Use return before function calling.

ScriptManager.RegisterStartupScript(this, GetType(), "FromDateSample", "return Noofdays();", true);

Button:

<asp:Button ... OnClientClick="return Noofdays();">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.