Following your comment I deduct, that the field can be present one or multiple times. In that case document.frmOrderReschedule.newSalesOrderNumber (or document.forms["frmOrderReschedule"].elements["newSalesOrderNumber"]) can return different types.
If there are multiple controls, it will return a collection, which will have a length property. If there is only one control, then it will return a direct reference to that control, which - obviously - doesn't have a length. That means, if you use that syntax you need to distinguish between the two variants (or even three variant, in case the field isn't there):
var x = document.forms["frmOrderReschedule"].elements["newSalesOrderNumber"];
if (x) {
if (x.length) {
alert("There are " + x.length + " controls.")
} else {
alert("One control with value: " + x.value);
}
} else {
alert("None");
}
Working example: http://jsfiddle.net/H4Lks/1/
document.getElementsByName('newSalesOrderNumber') on the other hand always returns a collection, even if there are none or one, so it always has a length.
document.frmOrderReschedule.newSalesOrderNumberreturn? What kind of element isnewSalesOrderNumber? How many are there actually? Can you show the HTML? BTW, you should avoid DOM 0 access of form elements as in your first example.document.forms["frmOrderReschedule"].elements["newSalesOrderNumber"]is better and more readable.document.frmOrderReschedule.newSalesOrderNumberis hidden element,it can be multiple depending upon requirementdocument.getElementById("newSalesOrderNumber")instead - this is most efficient way. To check the length of the value usedocument.getElementById("newSalesOrderNumber").value.length.