The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Asking about get text and replace text in Javascript

View previous topic View next topic Go down

Asking about get text and replace text in Javascript

Post by SarkZKalie on January 11th 2018, 3:01 pm

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
Code:
<a id="xyz" href="/profile?friend='ABC'&mode=editprofile&page_profil=friendsfoes"><img src="/smiley.png" /></a>
I wanna write a script that can get and return text from link, then replace 'ABC' by text I just get.
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 : http://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.
avatar
SarkZKalie
Forumember

Male Posts : 624
Reputation : 91
Language : English

http://rotavn.nstars.org/

Back to top Go down

Re: Asking about get text and replace text in Javascript

Post by SarkZKalie on January 13th 2018, 5:51 am

Bump Very Happy
avatar
SarkZKalie
Forumember

Male Posts : 624
Reputation : 91
Language : English

http://rotavn.nstars.org/

Back to top Go down

Re: Asking about get text and replace text in Javascript

Post by Apollo 2.0 on January 13th 2018, 3:01 pm

Code:
var getname = '{postrow.displayed.POSTER_NAME}';
var gettext = getname;
var result = gettext.replace(/\<a href="(.*?)"\>(.*?)\<\/a\>/gi, "$1 = link | $2 = username");
avatar
Apollo 2.0
Forumember

Male Posts : 54
Reputation : 5
Language : RO-10, EN-3, FR-1
Location : Romania

http://help.forumgratuit.ro/forum

Back to top Go down

Re: Asking about get text and replace text in Javascript

Post by SarkZKalie on January 14th 2018, 7:06 pm

Thank you for your quick respond! Could you tell me the way how this script works?
avatar
SarkZKalie
Forumember

Male Posts : 624
Reputation : 91
Language : English

http://rotavn.nstars.org/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum