Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Attempt at a Request
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
  • Pages:
  • 1
  • 2
Attempt at a Request
Tweet Topic Started: Jun 14 2009, 12:13 AM (399 Views)
Dorith Jun 14 2009, 12:13 AM Post #1
Member Avatar
Has just entered the Matrix

Posts:
2,069
Group:
Former Staff
Member
#1,854
Joined:
Dec 23, 2008
Ok so I tried doing this request: http://zbcode.com/topic/1796477/

But I sorta failed, and would like to know what went wrong.

I did these codes and neither worked:
Code:
 
<script type="text/javascript">
var a = document.getElementsByTagName("a");
var b = a.length
while (b--){
if (b.className == "maintitle"){
b.onclick.removeAttribute("href")
}
</script>

Code:
 
<script type="text/javascript">
var a = document.getElementsByTagName("a");
var b = a.length
while (b--){
if (b.className == "maintitle"){
b.removeAttribute("href")
}
</script>


Why doesn't that work?

Edit:
How would a post addition thing work? I got to this, then just got stuck:
Code:
 
var a = getElementsByClassName('c_post')
var b = a.length
while (b--){
if(a[b].location.href.indexOf('/search/?c=2\&mid=369577'){

Like I want it counting all the c_post which are the posts of the member originally. Through all the months and years and such.
Edited by Dorith, Jun 14 2009, 02:47 AM.
Posted Image
Posted Image
(Made emoticon using Codes Rock's Smiley Generator)
Offline Profile Goto Top
 
rockon1824 Jun 14 2009, 09:16 AM Post #2
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
When you get the length of something, you're getting a number. For example, if there are four links on a page and you do this:
Code:
 
var a = document.getElementsByTagName("a");
var b = a.length;
Then b will equal 4.

So, in your code, you're trying to tell it to change the class name of a number and then remove an attribute from a number. It's not working since numbers don't have classes and attributes. :P

What it should look like is:
Code:
 
<script type="text/javascript">
var a = document.getElementsByTagName("a");
var b = a.length
while (b--){
if (a[b].className == "maintitle"){
a[b].removeAttribute("href")
}
}
</script>
I'm not sure how familiar you are with arrays, but in this case, since you're referring to a specific piece of information in an array (i.e. the number "b" link on the page), you need to specify the array (a) and then tell it which array value to use (b). This is written like "a[b]".

There are a couple of other errors: you were also missing the closing bracket to the while loop, which is frequently one of the most common and frustrating errors in coding. :P Also, I think "maintitle" is the class of the div around the link in IF if I remember correctly. In this case, you would have to tell it to get the parent of the link using "parentNode":
Code:
 
var a = document.getElementsByTagName("a");
var b = a.length
while (b--){
if (a[b].parentNode.className == "maintitle"){
a[b].removeAttribute("href")
}
}
Posted Image
Offline Profile Goto Top
 
Gorgor Jun 14 2009, 10:25 AM Post #3
Hello

Posts:
1,187
Group:
Former Staff
Member
#2,728
Joined:
Apr 2, 2009
Coding language
PHP
Ooh, thanks for filling out my code request, it works perfectly :D
Offline Profile Goto Top
 
Dorith Jun 14 2009, 03:12 PM Post #4
Member Avatar
Has just entered the Matrix

Posts:
2,069
Group:
Former Staff
Member
#1,854
Joined:
Dec 23, 2008
Lol, I'm sorta learning the ropes. I keep "almost" getting the codes. Oh and I did add that other bracket in the Notepad++, guess I didn't add it here.

So when it's around a Div you gotta add parentNode? Is there like a link to things that are picky like that?

Also, what about my second code? How would I make a Javascript work ONLY in a specific url?
Posted Image
Posted Image
(Made emoticon using Codes Rock's Smiley Generator)
Offline Profile Goto Top
 
Reid Jun 14 2009, 11:39 PM Post #5
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
Code:
 
if (location.href.indexOf("some url")!=-1) {
... do something...
}
Also, getElementsByClassName is not a function. It does not exist, sadly..you have to loop through every element and check if the className is such and such. Like to remove any post that contains the word 'pneumonoultramicroscopicsilicovolcanoconiosis' you would have to do this:
Code:
 
var a = document.getElementsByTagName('td');
var b = a.length;
while (b--) {
if (a[b].className.indexOf("c_post")!=-1 && a[b].innerHTML.indexOf("pneumonoultramicroscopicsilicolvolcanoconiosis")!=-1) {
a[b].innerHTML = "";
}}
hehe
The Resource Board
Offline Profile Goto Top
 
Dorith Jun 15 2009, 03:41 PM Post #6
Member Avatar
Has just entered the Matrix

Posts:
2,069
Group:
Former Staff
Member
#1,854
Joined:
Dec 23, 2008
Should this work?
Code:
 
<script type="text/javascript">
var a = document.getElementsByTagName('td');
var b = a.length;
while (b--) {
if (location.href.indexOf("?c=2&mid=307261"){
document.write(a[b])
}
}
</script>
Posted Image
Posted Image
(Made emoticon using Codes Rock's Smiley Generator)
Offline Profile Goto Top
 
Reid Jun 15 2009, 04:12 PM Post #7
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
Dorith
Jun 15 2009, 03:41 PM
Should this work?
Code:
 
<script type="text/javascript">
var a = document.getElementsByTagName('td');
var b = a.length;
while (b--) {
if (location.href.indexOf("?c=2&mid=307261"){
document.write(a[b])
}
}
</script>
Yeah it should, although it will give you something like [object HTMLTableCellElement] or something weird like that. Also, you may want to wrap your entire code in the 'if' statement. It won't write anything if you're not on that page, but you could save some coding power and make it where it won't do anything if it's not on that page and skip the loop entirely...
Code:
 
if (location.href.indexOf("?c=32&mid=307261")!=-1) {
var a = document.getElementsByTagName('td');
var b = a.length;
while (b--) {
document.write(a[b]);
}}
The Resource Board
Offline Profile Goto Top
 
Viral Jul 4 2009, 11:52 AM Post #8


Posts:
342
Group:
Dedicated
Member
#48
Joined:
Jul 17, 2008
Coding language
PHP
Actually, it wouldn't. Without knowing what the code is supposed to do, your missing a clothing parenthesis on the if statement.

Posted Image
Offline Profile Goto Top
 
Choco Jul 4 2009, 01:36 PM Post #9
Member Avatar
¡ʎɹoʇɔɐɟ ʎʇıʌɐɹƃ ɐ uı pǝddɐɹʇ ɯ,ı 'dןǝɥ

Posts:
589
Group:
Admins
Member
#3,272
Joined:
Jun 30, 2009
Coding language
Everything
Viral
Jul 4 2009, 11:52 AM
Actually, it wouldn't. Without knowing what the code is supposed to do, your missing a clothing parenthesis on the if statement.
In the code that Reid just posted? Nope, the parentheses are fine. :)
Posted ImageIt's a magical world, Hobbes, ol'd buddy... ...let's go exploring!
In progress: Something Special ;)
Offline Profile Goto Top
 
Viral Jul 4 2009, 01:47 PM Post #10


Posts:
342
Group:
Dedicated
Member
#48
Joined:
Jul 17, 2008
Coding language
PHP
Quote:
 
if (location.href.indexOf("?c=2&mid=307261"){


check it again

Posted Image
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Code University · Next Topic »
Locked Topic
  • Pages:
  • 1
  • 2

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