• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

JQuery replace text is making all text from webapp the same

Participant ,
Jan 21, 2013 Jan 21, 2013

Copy link to clipboard

Copied

Hello, I'm hoping someone could give me a hand!

On this home page: www.largemouthfrog.net  I am running a WebApp called 'Testimonials' which produces a string of words/phrases based on checkbox selected items. They come into the page as: <li>...<div class="testimonial-comments1">brilliant! ,excellent! ,really good </div>...</li>

For each <li> there is a distinct set of words/phrases separated by a comma.

I want to remove the comma and replace with <br>

I have the following JQuery (see below) which replaces the comma with <br> BUT it takes the first <li> instance of

<div class="testimonial-comments1"> and repeats it again and again for all the other <li>'s. In other words:
"brilliant! ,excellent! ,really good" is duplicated repeatedly.

I've tried putting the JQuery inside the List layout of the WebApp but this does the same thing.

<script>

$(document).ready(function() {

var str = $(".testimonial-comments1").html().replace(/,/g, '<br>');

$(".testimonial-comments1").html(str);

});;

</script>

Any help would be much appreciated!

TOPICS
How to

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 22, 2013 Jan 22, 2013

Hi Wayne,

Your code is a bit too simplistic and it fails because it doesn't really

loop over all of the web app items and instead it grabs the content of the

first one and sets the rest of them with that content. I have created some

code which will get you started. Here it is:

$(".testimonial-comments1").each(function(index) { var tags_text =

$(this).text(); var split_text = tags_text.split(',');

console.log(split_text); });

You can see it here http://mgtrain.worldsecuresystems.com/tags

My class is simpl

...

Votes

Translate

Translate
Mentor ,
Jan 21, 2013 Jan 21, 2013

Copy link to clipboard

Copied

I looked at www.largemouthfrog.net  and it seems that you've managed to get this sorted.

-m

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 22, 2013 Jan 22, 2013

Copy link to clipboard

Copied

Hi Mario, unfortunately not resolved. The JQuery is working but the problem is that the WebApp is duplicating (repeating) the first webapp item data which is the:

brilliant!

excellent!

really good✓

Each testimonial does actually have its own unique set of words/phrases but these are not appearing, presumably because of the combo of JQuery and CSS. Just wondered if anyone else has solved this when working with WebApps in the way?

Thanks

Wayne

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 22, 2013 Jan 22, 2013

Copy link to clipboard

Copied

Hi Wayne,

Your code is a bit too simplistic and it fails because it doesn't really

loop over all of the web app items and instead it grabs the content of the

first one and sets the rest of them with that content. I have created some

code which will get you started. Here it is:

$(".testimonial-comments1").each(function(index) { var tags_text =

$(this).text(); var split_text = tags_text.split(',');

console.log(split_text); });

You can see it here http://mgtrain.worldsecuresystems.com/tags

My class is simply called "tags" and my list layout looks like this:

<h3 class="name">{tag_name}</h3>

<div class="tags">{tag_tags}</div>

Basically, that code will create an array of strings for each iteration.
All you have to do now is iterate over the array and add "
" to each

item, join the items into a string and  then set $(this).text() to that new

value.

That said, I'd recommend you to construct a UL form those options in this

case. It's a bit more semantic I think.

I may actually make this my first blog post at www.twoblokeswithapostie.com

Cheers,

Mario

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2013 Jan 28, 2013

Copy link to clipboard

Copied

Mario the code you provided me worked a treat! Thanks a million!

For anyone reading this blog, Mario is my go to man for all things complex coding, check him out at www.twoblokeswithapostie.com

The great thing is that I was able to take the WebApp function, bend it to my requirement and use JQuery to make it work on the other end. In case anyone wants to know, it is possible to store multiple checkbox input items as one dataset stored in one field and then output that (albeit with commas) in a way the JQuery could deal with the commas ...turning them into <br>s.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2013 Jan 28, 2013

Copy link to clipboard

Copied

Wayne, Your only touching the tip of the iceberg in what you can do with jQuery and BC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 28, 2013 Jan 28, 2013

Copy link to clipboard

Copied

LATEST

You should throw some examples our way, Liam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines