Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Using Javascript?
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
Using Javascript?
Tweet Topic Started: Jun 12 2009, 01:01 PM (301 Views)
Lout Jun 12 2009, 01:01 PM Post #1
Member Avatar


Posts:
402
Group:
Dedicated
Member
#2,400
Joined:
Feb 19, 2009
Hi guys, I want to use this code:-

Code:
 
<script type="text/javascript">
//Awards Modification in postdetails
//By slayer766 of thecodingzone.com

function Add(name,img,aname){
$(function(){
$(".c_username").contains(name).parent().next().find(".user_info").append("<dt>"+aname+":</dt><dd><img src='"+img+"'></dd>");
$(".spacer").appendTo(".user_info");
});}

Add("USER_NAME","IMAGE_URL","AWARD_NAME");
</script>


But with a slight difference, it's posted here, but on the last post it has been slightly changed to this:-

Code:
 
<script type="text/javascript">
//Awards Modification in postdetails
//By slayer766 of thecodingzone.com

function Add(name,img,aname){
$(".c_username:contains('"+name+"')").parent().next().find(".user_info").append("<img src='"+img+"' title='"+aname+"'>");
}

Add("Username" , "Image URL" , "Award Reason");
Add("Username" , "Image URL" , "Award Reason");
</script>


Which works well in testing. However, it will require lots of additional lines to be added to the board template in this format :- Add("Username" , "Image URL" , "Award Reason");

For each and every award.

So instead I've come up with this:-

Posted Image

Which will allow me to just paste up to 6 awards in the boxes and then only need one line of code for each user, which I would substitute with each additional award that they earn.

I've already worked out that by removing the Award Reason (but still leaving the "" intact) I can stop the hover showing.

Now, onto my question, is there a way I can replace the 40 or so lines of:- Add("Username" , "Image URL" , "Award Reason"); with a single piece of Javascript that I could upload as an attachment?

Hope that all makes sense :D
Posted Image
Offline Profile Goto Top
 
Reid Jun 12 2009, 01:39 PM Post #2
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Yeah. You copy all of the lines into notepad, save it as .js, then put this under the original code:
Code:
 
<script type='text/javascript' src='URL TO FILE HERE'></script>
The Resource Board
Offline Profile Goto Top
 
Lout Jun 12 2009, 01:41 PM Post #3
Member Avatar


Posts:
402
Group:
Dedicated
Member
#2,400
Joined:
Feb 19, 2009
Under the </script>, or just above it?

Sorry but I'm a bit of a biff with coding xD
Posted Image
Offline Profile Goto Top
 
Reid Jun 12 2009, 02:00 PM Post #4
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Under your original script. :P
The Resource Board
Offline Profile Goto Top
 
Lout Jun 12 2009, 02:05 PM Post #5
Member Avatar


Posts:
402
Group:
Dedicated
Member
#2,400
Joined:
Feb 19, 2009
Confused now, so it would be like this then :-
Code:
 
<script type="text/javascript">
//Awards Modification in postdetails
//By slayer766 of thecodingzone.com

function Add(name,img,aname){
$(".c_username:contains('"+name+"')").parent().next().find(".user_info").append("<img src='"+img+"' title='"+aname+"'>");
}

Add("Username" , "Image URL" , "Award Reason");
Add("Username" , "Image URL" , "Award Reason");
</script>
<script type='text/javascript' src='URL TO FILE HERE'></script>


But how would the second piece of JS know that it was connected to the first piece?
Posted Image
Offline Profile Goto Top
 
Reid Jun 12 2009, 02:12 PM Post #6
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
JS is all connected. :P

It's all one big page of JS to the engine.
The Resource Board
Offline Profile Goto Top
 
Lout Jun 12 2009, 02:56 PM Post #7
Member Avatar


Posts:
402
Group:
Dedicated
Member
#2,400
Joined:
Feb 19, 2009
I see, I'll try it out when the wife buggers off to bed and let you know how I get on :D
Posted Image
Offline Profile Goto Top
 
Lout Jun 17 2009, 01:56 AM Post #8
Member Avatar


Posts:
402
Group:
Dedicated
Member
#2,400
Joined:
Feb 19, 2009
Works like a dream by the way, thanks again :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:46 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy