![]() |
| Home | Demo | Services | Features | Help | User Forum | Blog | About | |
|
#1
|
|||
|
|||
|
Hi there, I am getting more crazy & frustrated the more I try with this bit of code I am trying to get working! I am by no means a coder, and am trying to get some javascript working. I basically have some variables being injected into a page, which I need to then change, by finding ',' and replacing with '.' - I have been playing with regexp but I haven't found any reference to these characters - anyone know a quick (and easy!) way of doing this on the fly?
TIA!!! |
|
#2
|
|||
|
|||
|
Replacing characters in a string is fairly easy with JS. This is a simple example. It would probably be best to set it up as a function that you can call whenever you need it. Here's a demo - http://www.jonra.com/css-demos/test/replace.html
<script type="text/javascript"> var str = "777,777,777"; newstr = str.replace(",",".","gi"); document.write(newstr); </script> The key function here is 'replace'. It takes the variable, which in this case is 'str' and replaces all instances of the defined character with the second character specified. In this case, a comma and a dot. The 'gi' is for global replacement. If you leave that out of the equation it only replaces the first instance. You could eliminate one step in the script by writing it as - document.write(str.replace(",",".","gi")); instead of first assigning it to a new variable as I did in the script. Last edited by jonra01; 03-07-2007 at 07:11 PM. |
|
#3
|
|||
|
|||
|
Perfecto! Thanks for the help, hopefully my sanity will return now!!!
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|