Compare first three characters of text box string value

Hi -
I'm trying to compare the first three digits of a textbox value to a fixed string.  I've tried to identify the first three characters by using the CharAt() function, but keep getting "object doesnt support this property or method' error.  Any suggestions?   Pnvalu value should be a string that looks like 'ABC123456'.   I need to compare the first three characters to make sure the user entered in the correct invoice number.

Code is part of a larger validation script.  Thanks for your help!  
function checkRadio(main)  {
var pnvalu = document.all.INVOICE.value;
var size = pnvalu.length;
var comp = "ABC"
var size3 = pnvalu.CharAt(size-3);
pnvalu = pnvalu.toUpperCase();
alert(size3);
 
}

Open in new window

MoJeaux39Asked:
Who is Participating?
 
hieloCommented:
var size3 = pnvalu.substr(0,3);
0
 
reb73Commented:
var size3 = pnvalu.tostring.substring(0,3)
0
 
hieloCommented:
>>but keep getting "object doesnt support this property or method' error.
The method is "charAt()" - lowercase "c" for "char", but it will only return ONE character, not a substring.
0
 
hieloCommented:
>>var pnvalu = document.all.INVOICE.value;
document.all will work only for IE. I suggest you give your input field an id:

<input id="Invoice" name="INVOICE" .../>
 
and use:
var pnvalu = document.getElementById("Invoice").value;

Open in new window

0
 
MoJeaux39Author Commented:
Thanks for the Assist!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.