JavaScript and AJAX Forum

I'm trying to combine these two scripts and get them to open in a new window. Any help / advice that you guys can offer is greatly appreciated. Basicly what I'm trying to do is that once a user imputs the contents into the 1st form field, a second form field will capitalize all the letters from the 1st form field and then convert that part of the form into the url and open the link in a new window. I've been working at this for a while and I can't get this to work correctly.

Here is the first. It works great by itself but for the life of me, I can't get it to open in a new window.

Thank you, Thank you, Thank you rocknbil. The script works like a charm. I have been trying for a couple of days to get this in place. I do have one other quick question. I'm trying to use a Regular Expression to find a certain word on my webpage. It is a unique word (17 characters,letters and numbers). Each one is different on each page. Can you tell me if this is the correct expression?

But . . . I have a feeling it still won't match exactly, and may still find other 17 character words (if there are any).

Examine what it does.

^ ... $ = the string you're searching STARTS WITH (^) and ENDS WITH $. If you're searching a whole page, I'm guessing the answer is "no, it doesn't work." This means the whole page must start and end with your pattern and contain nothing else.

/^abc$/ will match 'abc' but not " learn your abc's"

() = probably not needed, this is to group patterns and/or store the match in special variables, i.e. (this)(that) will have "this" in $1 and "that" in $2 (if a match is found.)

[] - character class - "if the pattern contains any of these characters"

a-zA-Z - match any letters. This is more efficient with the case insensitive modifier "i" (but works the same, so is OK . . .)

0-9 = match any digit, identical to \d

_- = characters to match - be cautious with the dash, as you can see above when in a character class it's often used to define a range, so I just always escape it (and the underscore as well. Probably not needed but that's what I do.)

{17} = a quantifier, match *exactly* 17 of the preceding characters.

so, all that being said, a more efficient version might be

/[a-z\d\_\-]{17}/i

But as mentioned, I doubt that's what you're after and may return other 17 character strings. If it's a unique word, why not just match the exact pattern?

Thanks for your reply. Here is what I'm looking for and part of my project. The 17 character word is actually VIN #'s for vehicles. Each Vin is unique and it contains letters and numbers in no specific order and they are always 17 characters long. I'm using the revised script you provided along with another script combined with Regex to search for the Vin # on the page, and plug that Vin # into the form field. Each page the script is on will have the same Vin # on it. I've tested the original expression and it does work but the vin # / 17 char. word has to be the first word and only word on the line for that expression to work. Below is a sample of the html on the page the script will be placed on.

With my current script, I know the user can copy and paste the vin # into the form field and click go and it will perform as it should. If for some reason the user types in the wrong vin #, then they will get an error page. I already have the script that will highlight the selected text and paste it into the form field from other test that I've done. That part works but, it is for specific characters that I know are in the page (JTNJ)for testing purposes. If I can auto fill that form field for the user based on a click, then I will have less chances for the user getting an error.

I know the user can copy and paste the vin # into the form field and click go and it will perform as it should.

Right, because the text field starts and ends with the pattern. When used that way, it's a good idea to trim off trailing and leading spaces (i.e., "help the user because they may not know" or may be copying and pasting from Word, which often adds a trailing space.)

The only thing I'd add to your regex is possibly make it case insensitive in the event someone enters it in lower case.

var reg = '/[A-Z0-9]{17}/i';

Optional, 0-9 and \d are identical. :-) The dash defines a a range, so it's appropriate for that - that is, everything between and including 2 to 8 would be [2-8]. Really it's the difference between saying "any digit" and "0 1 2 3 4 5 6 7 8 9" or "zero through nine".

RockNbil,I have another quick question that you may be able to help me with. I have been trying for a couple of days to get another Regex right and for the life of me I can't figure it out. BTW, the Vin# expression works fantastic!

Here is what I have so far. What I'm trying to capture with the expression is pricing. The expression I'm using is (abbr>[0-9,]+). The expression does capture what I want it to but I need it to do it globally. From what I've found online adding a /g is suppose to do just that. In every Regex tester that I've used, it does not work. The expression is basily broken if I do this (abbr>[0-9,]+)/g When I set the tester to check all or global and not use the /g it highlights everything like it is suppose to. I need the expression to check for all the prices on the page. I've used other expressions for pricing but the pages I'm using the expressions on, there are lots of different numbers on the pages. ie: engine size 2.4, vin #'s, jpeg photo links with numbers, etc.. Any advice on how I can accomplish my goal of just capturing pricing? Below is a snip of the website.