Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Compare first three characters of text box string value

Posted on 2009-02-08
5
Medium Priority
?
2,762 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:MoJeaux39
  • 3
5 Comments
 
LVL 25

Expert Comment

by:reb73
ID: 23585023
var size3 = pnvalu.tostring.substring(0,3)
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 23585030
var size3 = pnvalu.substr(0,3);
0
 
LVL 82

Expert Comment

by:hielo
ID: 23585055
>>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
 
LVL 82

Expert Comment

by:hielo
ID: 23585068
>>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
 

Author Closing Comment

by:MoJeaux39
ID: 31544298
Thanks for the Assist!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question