Re: Javascript and SubString

In reference to an earlier post, I am having some trouble formating my JavaScript correctly.

The previous post can be viewd here:

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/6bc83ddb4d5e682585256fb8005d8648?OpenDocument

I must be missing something. Here is the code I wrote in the onBlur event of my field:

document.forms[0].Pro1.value = String(document.forms[0].Pro1.value).substring(4,3);

The value I then enter in the field is pgh-010_1234567. When I leave the field and execute the script, the value is converted to just -. It’s removing everything but the -.

So, I altered the code to look like so:

document.forms[0].Pro1.value = String(document.forms[0].Pro1.value).substring(4);

when entering the same as above pgh-010_1234567, I am returned with 010_1234567.

Am I doing someing wrong or just misunderstanding the meaning of the script?

Regards,

-JS

Subject: re: Javascript and SubString

there are two jscript functions for substring

with the “substring” function, the variables you give it are ( string, start, end )

so, to get “010” you would do

document.forms[0].Pro1.value = String(document.forms[0].Pro1.value).substring(4,7);

“substr” is also a function and that one works like you’re trying to do it with variables of

(string, start, length )

Subject: RE: re: Javascript and SubString

OH(lightbulb) substring is using (string,start,END). I was thinking Length instead of end.

That totally fixed me up.

Thank you.

-JS