This is what i tried but it doesn't work!Help please
num = 999999999
numStr = new String(num);
newStr =
numStr.substring(0,numStr.length-1)+'-'+numStr.substring(numStr.length-1)
now, your code is :
<SCRIPT LANGUAGE="JavaScript1.2">
re = /(^\d)(\d+)/;
str = "99999999";
newstr = str.replace(re, "$1-$2"
document.write(newstr)
</SCRIPT>
------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
Your logic should work. It's just that your syntax is wrong.
In JavaScript, you can do a numeric to string casting by adding the number to a text string.
So
numStr = new String(num);
to be replaced by
numStr=''+num;
Then
newStr =
numStr.substring(0,numStr.length-1)+'-'+numStr.substring(numStr.length-1)
hey......it didn't work.......i am trying to format a field in a PDF document so it looks like that.....when i tried to put the script language tag in it told me i had a syntax error so i took it out and it still wouldn't work
"What does this [re = /(^\d)(\d+)/;] do?"
--> ah ah that's why i gave you the url BEFORE the code - anyway .... this is a reg exp and it states that the expression it's looking for is of the form : xy where x is A SINGLE number and y is 1 or more numbers
and then the "str.replace(re, "$1-$2"" line says to write the expression this way : x-y
so if str was "999999999" you'll get x=9 and y=99999999 and it'll display 9-99999999 ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
i am not just entering the information onto a form.....the information is coming from a vb program. the dash is in the vb program but on the PDF form it doesn't show up!
there was noting about a form in any thread here - or did i miss that ???
and where the info comes from is not a problem, as you're only using a string - and in javascript pretty much anything can be a string - so all code given here should be working regardless you're writing a form, reading datas from vb or from a text file or anything else
now i've got troubles understanding this : "the dash is in the vb program but on the PDF form it doesn't show up"
- the string you're reformatting is "xxxx" or "x-xxx" ???
- you've got a vb program, you'll send datas to a web page that is sending them to a pdf ???
- where do you want the string to be formatted : in the web page or in the pdf ?
------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
i am not reformatting. I want to custom format a textbox. The vb sends the info straight through to the PDF file....i want to format the textbox in the PDF file
pdf ??? i could have helped you for html but i don't know how pdf & javascript interact with each other
and about "my" fuction (the one i gave you above), is it running as you wish ? ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
what is not working ? it's not displaying anything or is it ? ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
you call my function with str="999999" and what writes is "999999" (same lenght) ? then it's a pdf problem, not related to javascript functions but rather to pdf display
and i'm totally unable to help you with pdf ! ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.