Go Back   Tech Support Forum > Design Forum > Web Design & Development


Code doesn't work

This is a discussion on Code doesn't work within the Web Design & Development forums, part of the Tech Support Forum category. The following code is supposed to switch div's (text1, text2, text3). The function mytext works when I put it in


Reply
 
Thread Tools Search this Thread
Old 05-19-2017, 06:50 PM   #1
TSF Enthusiast
 
Join Date: May 2007
Posts: 1,091
OS: Vista Home Premium



The following code is supposed to switch div's (text1, text2, text3). The function mytext works when I put it in a file by itself, but when it is embedded in the following code it doesn't work. The for loop in the function doesn't work.


HTML Code:
<script>

function mytext(thetext) {
	var subtext;
	var i;
	for (i=1; i < 4; i++) {
		subtext="text" + i;
		document.getElementById("subtext").style.visibility="hidden";
	}

		document.getElementById("thetext").style.visibility="visible";
			
}

</script>

<div class="container">
  <a href="#home">Home</a>
  <a href="#news">News</a>
  <div class="dropdown">
    <button class="dropbtn">Dropdown</button>
    <div class="dropdown-content">
      <a href="#" onclick="mytext(1)">Link 1</a>
      <a href="#" onclick="mytext(2)">Link 2</a>
	  <a href="#" onclick="mytext(3)">Link 3</a>
	 </div>	
    </div>
</div>

<div id="text1">
	<span style="font-family:helvetica; font-size:16pt; color:#ff9900; font-style:bold;">Text 1</span><br><br>
	
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking
 at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters,
 as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing 
 packages and web page editors now use Lorem Ipsum as their default model text
 
</div>


<div id="text2">
	<span style="font-family:helvetica; font-size:16pt; color:#ff9900;">Text 2</span><br><br>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</div>


<div id="text3">
	<span style="font-family:helvetica; font-size:16pt; color:#ff9900;">Text 3</span><br><br>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>
</body>

</html>
BrentC is offline   Reply With Quote
Sponsored Links
Advertisement
 
Old 05-20-2017, 10:44 AM   #2
TSF Enthusiast
 
Join Date: May 2007
Posts: 1,091
OS: Vista Home Premium



Solution:

I didn't set the visibility of the divs in the css.
BrentC is offline   Reply With Quote
Old 05-20-2017, 11:11 AM   #3
TSF Enthusiast
 
Join Date: May 2007
Posts: 1,091
OS: Vista Home Premium



I also changed the function as follows:

Code:
var lastdiv = 1;

function mytext(thetext) {
	var subtext;

	if (lastdiv != thetext) {
		subtext= "text" + lastdiv ;
		document.getElementById(subtext).style.visibility="hidden";
		lastdiv = thetext;
		subtext= "text" + thetext ;
		document.getElementById(subtext).style.visibility="visible";
	}			
}
BrentC is offline   Reply With Quote
Old 05-20-2017, 04:12 PM   #4
TSF Enthusiast
 
Join Date: May 2007
Posts: 1,091
OS: Vista Home Premium



Correction:

I had the opacity of the divs set to 0 in the css.
BrentC is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecter in my win 8.1 sync settings or ???
Ok so for some time now malware bytes is blocking my metro/modern/etc IE of windows 8.1 from redirecting to androrat.xx.xx (put x's for safety but it's co.cc) and to ncrypt.xx (it started with ncrypt but today i saw the androrat one and - kinda forgot about this one but i do know it might be .in or...
Medicated Virus/Trojan/Spyware Help 26 07-15-2015 07:04 PM
Blue Screens on Boot
Hey guys... I've been trying unsuccessfully to solve some BSODs that have been showing up on a 32 bit Windows Vista Home Premium Dell Inspiron 1545 here. It can boot up in safe mode, but in normal mode it gets to the desktop briefly and then immediately blue screens and restarts. I used...
niko381 BSOD, App Crashes And Hangs 11 06-17-2015 08:08 PM
Multiple BSODs - Win8 x64 - can't troubleshoot myself
Hi, I'm an engineering student and I'm trying hard to troubleshoot my BSODs problems born with the installation of Windows 8 x64 and/or of a new SSD. I see this forum is full of highly technical answers I liked and also good helpers so I chose to register for your help. Let's follow your...
cmatte BSOD, App Crashes And Hangs 20 07-18-2013 07:18 AM
BSOD after few minutes of gaming
Hello, and thanks in advance for taking the time to help. First off, I couldn't find a thread with specific instructions on who to acquire all the specific log files for Windows XP - it seems the stickies only pertain to Windows 7 / Vista. If someone could point me in the right direction, I'll...
Deamon615 BSOD, App Crashes And Hangs 37 11-04-2012 02:18 PM
[SOLVED] Network card or network driver causing BSOD
Hi so recently ive been having tons of problems with my computer frequently BSODing its getting really really annoying, im sorta scared to use the internet on my computer when i don't have to because it causes my computer to bluescreen, typically it happens when im on the internet and it usually...
Ravenclaw Cabling and Network Cards 8 12-19-2011 07:14 PM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2


All times are GMT -7. The time now is 09:08 PM.


vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Copyright 2001 - 2015, Tech Support Forum

Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts

 

Partially Powered By Products Found At Lampwrights.com