2
if (Trim(document.getElementById("txtAffiliateName").value)=""){
       alert("Please enter 'Affiliate Name'.");
       document.getElementById("txtAffiliateName").focus();
       return false;
}

When I use this code in ASP.NET it give the alert :

Microsoft JScript runtime error: Cannot assign to a function result

With continue,ignore,break options,when I click on continue it goes to page load and working properly and when I click on break it stops the execution.

if (document.getElementById("txtAffiliateName").value="") {
       alert("Please enter 'Affiliate Name'.");
       document.getElementById("txtAffiliateName").focus();
       return false;
}

When I remove the Trim the alert error message is not showing. But the TextBox value will be empty on button click. What is the solution for this?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • 2
    `=` is assignment `==` is comparison. – seenukarthi Aug 11 '15 at 05:51
  • check this [link](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons) to know why is it better to use === than == – shreesha Aug 11 '15 at 07:01

1 Answers1

0

You should use Comparison Operator ==.

Change this:

if (Trim(document.getElementById("txtAffiliateName").value) = "")

To this:

if (Trim(document.getElementById("txtAffiliateName").value) == "")
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109