First convert the user's input value to uppercase (or lowercase), and then compare:
var name = Document.form1.txtUserName.value.toLowerCase ();
if (name = = "Urname")
{
//statements go to here.
}
JavaScript has two kinds of equality operators. One is completely backwards compatible, the standard "= =", if two operand types are inconsistent, it will automatically type the operand at some time, consider the following assignment statement:
var stra = "I love you!";
var strb = new String ("I love you!");
The two variables contain the same sequence of characters, but the data types are string, the latter is object, and when you use the "= =" operator, JavaScript tries various values to detect whether the two are equal in some case. So the following expression results in True:stra = = Strb.
The second operator is "strict" "= = =", it will not be so tolerant when the evaluation, will not be type conversion. So the value of the expression stra = = = Strb is False, although both variables hold the same value.
Sometimes the logic of the code requires you to determine whether two values are not equal, there are also two choices: "!=" and Strict "!==", their relationship is similar to "= =" and "= =".
Discuss:
"= =" and "!=" look for the matching of values as much as possible, but you might want to make explicit type conversions before you compare them to "help" them get the job done. For example, if you want to determine whether a user's input value (a string) equals a number, you can let "= =" help you complete the type conversion:
if (Document.form1.txtAge.value = = Somenumericvar) {...}
You can also convert in advance:
if (parseint (document.form1.txtAge.value) = = Somenumericvar) {...}
If you are more accustomed to strongly typed programming languages (such as C#,java, etc.), you can extend your habits (type conversions) here, which will also enhance the readability of the program.
One thing to note is the locale of the computer. If you use "<" and ">" to compare strings, JavaScript compares them as Unicode, but it is clear that people do not read text as Unicode when browsing the Web: In Spanish, for example, in traditional order, "ch" will be ranked as a character between "C" and "D". Localecompare () provides a way to help you use character collation under the default locale.
var strings; An array of strings to sort, assuming that the initialization
strings.sort (function (a,b) {return a.localecompare (b)}) is already initialized;//Call the sort () method to sort