Avago
10-03-2005, 11:37 AM
I'm quite new to working with javascript, and I need a bit of help. I'm currently using a blogging utility (blogger) that produces an 18 digit ID number for each post. I'd like to take each post's ID number and replace it with a link based on that number.
example:
-----
post1
misc text
025687569321548961
post2
misc text
547896358754198647
-----
to
-----
post 1
misc text
<a href="Post1specificLink.htm">link</a>
post2
misc text
<a href="Post2specificLink.htm">link</a>
-----
The code to generate the links is already written, I just need a way to find the 18 digit numbers, send the numbers to a function, and replace the numbers on the page with whatever the function returns. I've been playing around a bit with various implements of or RegExp to see what can be done, but I'm just shooting in the dark. Absolutely any nudge in the right direction would be hugely appreciated.
function swapit(){
bodyText = document.body.innerHTML;
var parsebdt = bodyText.replace(/\d{18}/g,"TEST");
document.body.innerHTML = parsebdt;
}
///
function arraytest(){
var bodyText = document.body.innerHTML;
myArray = /\d{18}/g.exec(bodyText);
var parsebdt = bodyText.replace(/\d{18}/g,myArray[1]);
document.body.innerHTML = parsebdt;
}
^ replaces all 18 digit numbers with "undefined"
example:
-----
post1
misc text
025687569321548961
post2
misc text
547896358754198647
-----
to
-----
post 1
misc text
<a href="Post1specificLink.htm">link</a>
post2
misc text
<a href="Post2specificLink.htm">link</a>
-----
The code to generate the links is already written, I just need a way to find the 18 digit numbers, send the numbers to a function, and replace the numbers on the page with whatever the function returns. I've been playing around a bit with various implements of or RegExp to see what can be done, but I'm just shooting in the dark. Absolutely any nudge in the right direction would be hugely appreciated.
function swapit(){
bodyText = document.body.innerHTML;
var parsebdt = bodyText.replace(/\d{18}/g,"TEST");
document.body.innerHTML = parsebdt;
}
///
function arraytest(){
var bodyText = document.body.innerHTML;
myArray = /\d{18}/g.exec(bodyText);
var parsebdt = bodyText.replace(/\d{18}/g,myArray[1]);
document.body.innerHTML = parsebdt;
}
^ replaces all 18 digit numbers with "undefined"