Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Please help me improve this code!
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
Please help me improve this code!
Tweet Topic Started: Nov 8 2008, 04:17 PM (271 Views)
rockon1824 Nov 8 2008, 04:17 PM Post #1
Member Avatar
I never know what to put for my member title. =(

Posts:
186
Group:
Member
Member
#424
Joined:
Aug 2, 2008
Coding language
HTML/CSS
A little background info: I run a music forum on Zetaboards, and users can submit music-related articles and reviews to be put on our adjoining website. I wanted to make it so you could find links to all the articles and reviews a user has submitted in their profile on the forum.

So I set up two custom profile fields, titled Articles and Reviews, respectively. Then I edited these profile fields for each user who had submitted an article and/or review with either "usernameart" or "usernamerev" (for example, mine would be "rockon1824art" in my Articles profile field and "rockon1824rev" in my Reviews profile field). Then I drew up this code, which works, but it's pretty inefficient (my coding skills are very limited):
Code:
 
$(".profile td:contains('usernameart')").html('<a href="http://example.com">Article Title</a><br />');
I have one of these lines for each user who has submitted an article and each user who has submitted a review. Considering many users have submitted more than one article/review, these lines increase with multiple links, making for a pretty unruly JavaScript file. (Here's the current one.)

How could I pare this down to make it easier to add these links to users' profiles? So far I've come up with this, which is a little better, but not by much:
Code:
 
function Cont(name,html){
$(function(){
$(".profile td:contains('+name+')").html('+html+');
});}

Cont("usernameart","<a href="http://example.com">Article Title</a><br />");
It would be best to have it so I could add the links through a function as well, but I'm not sure how to do that.

Any help with this would be greatly appreciated. Thanks. :)
Posted Image
Offline Profile Goto Top
 
Fission Nov 8 2008, 08:03 PM Post #2
Member Avatar
Weegee

Posts:
45
Group:
Member
Member
#1,120
Joined:
Oct 4, 2008
Coding language
Everything
Self promotion go! Linkable Profile fields. So easy you might get pelted with stones for using an over-used saying.
0110110101100101
 
There are 10 types of people in this world: Those who know binary, and those who don't.

Floatboxes. They float. || Posted Image Posted Image

Posted Image
Offline Profile Goto Top
 
rockon1824 Nov 8 2008, 09:05 PM Post #3
Member Avatar
I never know what to put for my member title. =(

Posts:
186
Group:
Member
Member
#424
Joined:
Aug 2, 2008
Coding language
HTML/CSS
That's a great code, but since it's for 1-line text fields, it wouldn't really work if the user has more than one article or review. :(
Posted Image
Offline Profile Goto Top
 
Fission Nov 8 2008, 11:00 PM Post #4
Member Avatar
Weegee

Posts:
45
Group:
Member
Member
#1,120
Joined:
Oct 4, 2008
Coding language
Everything
So you are using a text box? That's different... I could edit my code a lot bit to make it read through the contents, looking for the delimiter (a comma) and add anchor tags around it. However, it is a bit too late for me to do that now; I'll get on it tomorrow.
0110110101100101
 
There are 10 types of people in this world: Those who know binary, and those who don't.

Floatboxes. They float. || Posted Image Posted Image

Posted Image
Offline Profile Goto Top
 
rockon1824 Nov 9 2008, 08:32 AM Post #5
Member Avatar
I never know what to put for my member title. =(

Posts:
186
Group:
Member
Member
#424
Joined:
Aug 2, 2008
Coding language
HTML/CSS
Yeah, I'm using a text-box for it.

Thanks a ton, I really appreciate the help. :D
Posted Image
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:45 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy