Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a string of text/link???

Status
Not open for further replies.

guiltyverdict

Technical User
Feb 25, 2003
20
US
Does anybody know how to do the following?

Say I have the following links (it is a directory structure):

HOME : LEVEL 1 : LEVEL 2 : level 3

Is there a way with javascript to take out (delete or not show)
" LEVEL 1 :"??
I dont want users to be clicking on it. I have tried many javascript sites and I cant find anything even close to it.

Thank you for any information in advance!
 
If it is a print out of a directory structure generated by the web server then you have to edit the server templates. Apache has something called fancy indexing to do this but your host may not allow editing.

If it is your web page then you can dissable, hide, delete or not render various elements dynamically using DHTML.

Which solution would you prefer? :)

If I assume it is a regular link and it has an ID, something like this. I'll stick it a SPAN to make the examples easier:

<span id=&quot;link_page1&quot;><a href=&quot;page1.html&quot; page1</a></span>

Here is how I would hide the link:
document.getElementById('link_page1').style.visibility='hidden';

Here is how I would delete the link:
document.getElementById('link_page1').innerHTML=&quot;&quot;;

You didn't say when it should hide/delete the link so I cannot really complete the answer at this time but it is definately possible.

When I stop posting here, this will be just like all those other Javascript sites. LOL ;)

j/k :p
 
I should have explained this better:

the directory structure is all produced by cgi. I can change the HOME link to read whatever i want. but the rest of the structure is produced in the output by a routine:
Code:
<A!SNIPPET NAME=ODP_CATPAGE.NAVBAR>
	<table align=center width=&quot;100%&quot; cellpadding=0 cellspacing=0>
	   <tr>
		  <td align=left valign=top>
				-------------------This is the top level cat. (home)---------------------------
				<a href=&quot;A!CATURL!&quot;>A!CATNAME!</a> <b>:</b>
				------------------------End of top level cat. name-----------------------------

				-------------------Start of sub category loop----------------------------------
			  	<A!LOOP.NAVCAT><a href=&quot;A!NAVCATURL!&quot;>A!NAVCATNAME!</a> :</A!LOOP.NAVCAT>
				-----------------------End of sub categories-----------------------------------

				---------------------Current directory----------------------------------------- 
				A!CURCATNAME! 
				----------------------End current directory-------------------------------------
		  </td>
	  </TR>
	</table>
</A!SNIPPET>

There has to be some way to hide a string of text like
<a href&quot; this out</a>.

I could not use the div id because it would be applied to all the other subdirectories. and they would all be hidden then.

Ill give you an example:
take a look at this website->
the directory reads like this:
Top: Arts: Music
what i would like is to take out the &quot; Arts:&quot; part of the directory.
 
grr i didnt mean div id i meant span id.
Also maybe i could do the span id if there was a way for the span id to be generated from javascript.

for instance when its generating the link, have javascript increment numbers or letters for each span id. Like this:
Code:
<span id=&quot;1&quot;></span>
<span id=&quot;2&quot;></span>
<span id=&quot;3&quot;></span>

then i could hide it with your code above. I know alot more about html than javascript. So im not sure if you can do that.
 
That does complicate matters slightly but technically doesn't change anything :)

If I were in your shoes I would edit the sub catagory loop or rewrite that section of the script. Why generate what isn't needed?

Failing that, we add some bloat. To keep it simple, drop this in at the bottom of the page.

<SCRIPT>
document.getElementsByTagName('A').style.visibility='hidden';
</SCRIPT>

NOTE: Replace the value: with a number representing the specific link that you want to remove.

The first link on the page is called [0], the second link is [1], the third is [2] and so forth :)

Now in CGI/PERL...

# May need to update value to remove the correct link
print &quot;<SCRIPT>\n&quot;;
print &quot;document.getElementsByTagName('A').style.visibility='hidden';\n&quot;;
print &quot;</SCRIPT>\n&quot;;

Add that near the bottom of the CGI script before something that should look like:

print &quot;</HTML>\n&quot;;

This isn't a PERL forum so don't blaim me if it generates an error. Does look OK to me though.

Good luck! :)
 
Humn. Sorry about the italic text! :(

QUOTE: for instance when its generating the link, have javascript increment numbers or letters for each span id. Like this.

You could indeed increment the id= in PERL. It would look something like this:

Code:
# new variable added to top of script
$i=0;

# this loop has been edited
print &quot;<A id=\&quot;$i++\&quot; href=\&quot;[URL unfurl="true"]http://\&quot;>[/URL] my link </A>\n&quot;;

Note though that I haven't programmed in PERL for a very long time and I'm prone to making silly mistakes :(
 
Code:
AAARGH!!! Silly forum. Take 2: Note the difference.

[i] <-- essential piece of script not in previous post.


<SCRIPT>
document.getElementsByTagName('A')[i].style.visibility='hidden';
</SCRIPT>

NOTE: Replace the value: [i] with a number representing the specific link that you want to remove.

The first link on the page is called [0], the second link is [1], the third is [2] and so forth :)

Now in CGI/PERL...

# May need to update value to remove the correct link
print &quot;<SCRIPT>\n&quot;;
print &quot;document.getElementsByTagName('A')[i].style.visibility='hidden';\n&quot;;
print &quot;</SCRIPT>\n&quot;;
 
so how would i correctly take out the 16th link??? Because im not quite sure what you mean when you say replace the value with a number. the only value i see in your above code
Code:
<SCRIPT>
document.getElementsByTagName('A').style.visibility='hidden';
</SCRIPT>
is A, but that refers to the <a> tag.
 
ok it successfully takes the link out, but it leaves a blank space in its place. i used the document.getElementsByTagName way. i quess i can deal with that. If i used the span id way would it remove the white space, from where the link used to be??

Thank you very much.
 
Yup, you got it. If you use the SPAN and innerHTML=&quot;&quot;; it should display nothing :)

Remember where you found the solution ;)
 
Oh wait! Try this first...

<SCRIPT>
document.getElementsByTagName('A').style.display='none';
</SCRIPT>
 
You are a hero in my eyes!!!! Thank you very much. The white space is gone and its now working the way i wanted!

 
wait i spoke too soon... it gives me an error and i found out that you can only use visible, hidden, and inherent as variables. Is there a way to call it from the onload body??

 
&quot;it gives me an error&quot; - what error? :(

I assure the concept is fine - but javascript will never be as robust as killing the link in CGI.

Double check the source code to see how it was generated by the CGI - there may be a glitch or the remained or something like that.

It may produce an error if the script renders before the links - that's why I suggested dropping it in just above </HTML>

You certainly can use onload=&quot;hideLink();&quot; and that will have a similar end result - making the script take effect after the links have rendered.

<SCRIPT>
// Remember to update that when editing this page
// Removes that anoying link
function hideLink() {
document.getElementsByTagName('A').style.display='none';
}
</SCRIPT>
 
My problem with the cgi is that i didnt make the script so its hard to find the line of code that is looping the categories. even worse is that they didnt put in line breaks into the script so it makes it that much harder for me.

I was loading the script through the template the script uses. When i replace visibility='hidden' with visiblity='none' i get this error:

Could not get the visiblity property. Invalid argument.

But if i use the hidden, it works but leaves the whitespace behind.
 
The two arguments being considered are:

1. visibility='hidden'
2. display='none'

There is no such thing as visibility='none'

Explanation:

visibility : Affects how the object is rendered/displayed
display : Whether or not to render/display the object

visibility : hidden/visible/inherited(default)
display : none
 
Bada bing bada boom-----> it works no more whitespace!!!!!!! Sorry i didnt see that you changed it to display='none'. Makes more sense now. You are still my hero and thanks for all the help!

Again thz!
Dan R.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top