I am looking to automatically format what a user enters in a field on a form within a browser. JavaScript onBlur seems to be a cool place to do this, but my JavaScript skills are quite weak.
A LotusScript example of what I am looking to do would be like this:
newpro = Mid(docWeb.Pro1(0),5,3) & “0” & Right(docWeb.Pro1(0),7)
In this case, I am just extracting several parts of what the user entered and adding it to my new variable.
Anyone know how to convert that to JavaScript so I can make the change right in front of the user on the page, rather than in the back-end with my LotusScript?
Regards,
-Jeremy
Subject: JavaScript - left, right, mid, length
It’s all a “Mid” in Javascript:
string.substring(startIndex,length)
Keep in mind that the index begins at zero, not one.
Subject: RE: JavaScript - left, right, mid, length
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