Solved

jquery using csv to produce list with unique href per item

Posted on 2012-12-23
6
341 Views
Last Modified: 2012-12-28
Hi,
I'm trying to adapt a code snippet I had gotten from here.

What I need to achieve is to produce a ul list with data in each li item and a unique href for each item using csv data on the site.

Here's what I have
<section class="tag"><strong>TAGGED IN: </strong><ul><span>item1,nextItems2,anotherItems3</span></ul>


Here's what need to be produced
<section class="tag">
<strong>TAGGED IN: </strong>
<ul>
<li><a href="SameDomainURL/search-results.html?item1">item1</a></li>
<li><a href="SameDomainURL/search-results.html?nextItems2">nextItems2</a></li>
<li><a href="SameDomainURL/search-results.html?anotherItems3">anotherItems3</a></li>
</ul>

Here's the code I've tried to append but doesn't quite work:
$('.tag span').each(function(){
	var currentList = $(this);
	var itemsArray = currentList.text().split(",");
	//Loop through the array and add a li a href element
	$.each(itemsArray , function(index, value) { 
		var newLI = $("<li>").html($("<a>").html(value).attr('href', '/site-search-results.html?category=').html(value));
		currentList.append(newLI);
	});
});

Open in new window


What it isn't doing but I need it to is:
1. strip the original csv data just leaving the formatted data.
2. Add the item value as unique value per item to the url href after the ?

Help appreciated...Christmas is nearly here! and I need to finish!
Regards
Lee
0
Comment
Question by:boxhedge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38716633
Have a look at this project http://code.google.com/p/jquery-csv/
0
 

Author Comment

by:boxhedge
ID: 38716707
Thanks but not what I'm after.
Just need this one use and the specific requirements of what I have explained.
If padas or anyone else can be of more help it would be appreciated,
Regards
Lee
0
 

Accepted Solution

by:
boxhedge earned 0 total points
ID: 38716889
Sorted it. Slightly different approach

	var propCatList = $('.tag ul').text();
	itemsArray = propCatList.split(",");
	$('.tag ul').html('');
	$('.tag ul').append('');
	$.each(itemsArray , function(index, value) { 
	$('.tag ul').append('<li><a href="/site-search-results.html?category='+ value +'"><span>' + value + '</span></a></li>');
	});

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:boxhedge
ID: 38716891
I've requested that this question be closed as follows:

Accepted answer: 0 points for boxhedge's comment #a38716889

for the following reason:

Because it is and expert posted generic answer without really thinking it through. Once an expert posts a single comment it greatly reduces chance of someone elses involvement
0
 

Author Comment

by:boxhedge
ID: 38716892
Because I provided the solution and expert posted generic answer without really thinking it through. Once an expert posts a single comment it greatly reduces chance of someone elses involvement particularly in my short timescale.
0
 

Author Closing Comment

by:boxhedge
ID: 38726420
Because I provided the solution and expert posted generic answer without really thinking it through. Once an expert posts a single comment it greatly reduces chance of someone elses involvement particularly in my short timescale.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allow link tag to be submit like form 15 58
Save data in two Database, Asp 2 67
center text in div with CSS3 2 27
Can't see json data in ajax call to Highcharts 2 25
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question