Asking about get text and replace text in Javascript
3 posters
Page 1 of 1
Asking about get text and replace text in Javascript
Hello
Im still learning a little Javascript language but after failed to install this add-on to my site, I came up with an idea.
For example I have a hyperlink text
Why do I must use a variable?
- Cuz '{postrow.displayed.POSTER_NAME}' will only work in viewtopic_body template and return a text with link included itself. Example : https://help.forumotion.com/u1, not a simple text.
So my complete hyperlink html code will be like this
I would appreciate any help.
Thank you for reading.
Im still learning a little Javascript language but after failed to install this add-on to my site, I came up with an idea.
For example I have a hyperlink text
- Code:
<a id="xyz" href="/profile?friend='ABC'&mode=editprofile&page_profil=friendsfoes"><img src="/smiley.png" /></a>
- Code:
var getname = '{postrow.displayed.POSTER_NAME}'; // <a href="http://domain.com/u1">Volunteer</a>
var gettext = getname.text; // return Volunteer
var result = replace(/'ABC'/gi, "gettext");
Why do I must use a variable?
- Cuz '{postrow.displayed.POSTER_NAME}' will only work in viewtopic_body template and return a text with link included itself. Example : https://help.forumotion.com/u1, not a simple text.
So my complete hyperlink html code will be like this
- Code:
<a id="xyz" href="/profile?friend=Volunteer&mode=editprofile&page_profil=friendsfoes"><img src="/smiley.png" /></a>
I would appreciate any help.
Thank you for reading.
Re: Asking about get text and replace text in Javascript
- Code:
var getname = '{postrow.displayed.POSTER_NAME}';
var gettext = getname;
var result = gettext.replace(/\<a href="(.*?)"\>(.*?)\<\/a\>/gi, "$1 = link | $2 = username");
Re: Asking about get text and replace text in Javascript
Thank you for your quick respond! Could you tell me the way how this script works?
Re: Asking about get text and replace text in Javascript
-> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
-> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
He used the string's replace method with regular expressions.
---
In the example below, I will replace all digits with
:
... And so on:
To learn more, read the regular expression documentation.
-> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
He used the string's replace method with regular expressions.
---
In the example below, I will replace all digits with
|
- Code:
var str = 'I can count from 1 to 10.';
str = str.replace(/\d/g, ' [D] ');
console.log(str); // I can count from [D] to [D] [D] .
... And so on:
- Code:
var str = 'I can count from [D] to [D] [D] .';
str = str.replace(/\s\[D\]\s/gi, function () {
return Math.floor(Math.random() * 20);
});
console.log(str); // I can count from 14 to 193.
// The numbers are ramdom!
To learn more, read the regular expression documentation.
Similar topics
» Replace text to emoticon using javascript
» Text replace with another one
» Text Replace
» Navbar text replace
» Replace text to emoticon (on Forumotion)
» Text replace with another one
» Text Replace
» Navbar text replace
» Replace text to emoticon (on Forumotion)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum