JavaScript - Visibility Control Question From A Complete Noob.
Every year or two, I want to do something SIMPLE via JS, and each time it's like i've never been there before
I simply want a button to show/hide something on click, and I THINK I'm close, but it's not quite working. Here's what I'm toying with. Code: <html> <head> <script type="text/javascript"> function showHide("idName") { if(document.getElementById("idName").style.visibility=="hidden") { document.getElementById("idName").style.visibility=="visible"; } else { document.getElementById("idName").style.visibility=="hidden"; } } </script> </head> <body> <button type="button" onclick="showHide(1)">Click Me!</button> <div id="1" "style=visibility:hidden;"><p>this is the stuff.</p></div> </body> </html> How do I get the button to make that div (in)visible?? ~Mo Similar TutorialsI would like to use this code for multiple object on a single page. Code: <SCRIPT LANGUAGE="JavaScript"> function ClipBoard() { holdtext.innerText = copytext.innerText; Copied = holdtext.createTextRange(); Copied.execCommand("Copy"); } </SCRIPT> <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink"> Text of stuff </SPAN> <TEXTAREA ID="holdtext" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> The problem is im not sure how to get more than 1 SPAN ID to work with the script. any help would be great! I'm a total noob who decided to learn som web programming, I hope it's okey to post such questions here. I've written a script to learn how to fill in a value into a textarea by a button click. (See below.) I get it to show the selected number of each button, however the numbers just flashes and disappers right away. I want it to stay in the textarea. How do I do that and why does this problem appear? Head section <script type="text/javascript"> function calculon(i) { document.forms['siffror'].elements['test'].value = i; return; } body section <form name="knappar"> <input name="sifferknapp" type="submit" value=1 onClick=calculon(this.value)> <input name="sifferknapp" type="submit" value=2 onclick=calculon(this.value)> <input name="sifferknapp" type="submit" value=3 onclick=calculon(this.value)><br /> <input name="sifferknapp" type="submit" value=4 onclick=calculon(this.value)> <input name="sifferknapp" type="submit" value=5 onclick=calculon(this.value)> <input name="sifferknapp" type="submit" value=6 onclick=calculon(this.value)><br /> <input name="sifferknapp" type="submit" value=7 onclick=calculon(this.value)> <input name="sifferknapp" type="submit" value=8 onclick=calculon(this.value)> <input name="sifferknapp" type="submit" value=9 onclick=calculon(this.value)><br /> </form> Could someone please change this line so that it respects the global namespace: Code: var selected = students.options[students.selectedIndex].value; The error console is telling me to use document.getElementById but I don't know where to put it. Thanks. Very new to javascript, so I apologize in advance. I honestly tried to figure this out on my own, and I'm just not able. I'm trying to create a family tree online that has several other related family charts. I want each person's name and birth year to be stored in javascript variables, then I want to be able to just go through the tree, and put the persons name once, and have it put the appropriate name and birthyear in the little boxes that the css is creating. In the js file... I would do this for each family member. Code: var johnname = "John Smith"; var johnbirthyear = "Jan 1 1930"; var janename = "Jane Doe"; var janebirthyear = "Jan 1 1940"; var mikename = "mike wilson"; var mikebirthyear = "Jan 1 1950"; var saraname = "sara johnston"; var sarabirthyear = "Jan 1 1960"; In the HTML file... Code: <div id = "boybox"> <script type="text/javascript"> id = "john"; <!-- this is the only thing I want to have to change --> name = id+"name"; document.write(name); </script> <div id = "year"> <script type="text/javascript"> birthyear = id+"year"; document.write(birthyear); </script> </div> </div> So I thought I had it all figured out. I thought that the above would take the id of John that I added, go to the line that sets the name, add john to the word name, and then document write the variable of johnname from the js file. I know you're laughing at me because of course it instead made the value of name to johnname, then wrote the word johnname in the box. Can anyone point me in the right direction please? ultimately I want to go through and be able to just type the persons name in the html for that box once, and have it update with their appropriate info. Thanks, and sorry for such a rookie question. Hi all, I sincerely apologise for the noob question. I have search and searched for an answer but to no avail, so I hope someone on here can help. I'm trying to get a fisheye verticle menu working. I've found somethin which fits the requirement he http://zendold.lojcomm.com.br/ifisheye/ and tried to make it work. It just doesn't. I've tried different versions of mootools etc but I think I'm missing something really stupidky simple. I'd really appreciate it if someone could have a look at my temp page (http://www.parkerbs.com/home1.htm) and point me in the right direction. Many thanks in advance. Paul Hi all, I'm desperately trying to figure out how to "transform" Javascript commands into HTML code. Excuse my noobness but I really know nothing about Javascript. Basically, I have this Google API Search code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My Google AJAX Search API Application</title> <script src="http://www.google.com/jsapi?key=CUT"></script> <script language="Javascript" type="text/javascript"> //<![CDATA[ google.load("search", "1"); function OnLoad() { // Create a search control var searchControl = new google.search.SearchControl(); // Add in a full set of searchers var localSearch = new google.search.LocalSearch(); searchControl.addSearcher(localSearch); searchControl.addSearcher(new google.search.WebSearch()); searchControl.addSearcher(new google.search.VideoSearch()); searchControl.addSearcher(new google.search.BlogSearch()); // Set the Local Search center point localSearch.setCenterPoint("New York, NY"); // Tell the searcher to draw itself and tell it where to attach searchControl.draw(document.getElementById("searchcontrol")); // Execute an inital search searchControl.execute("Google"); } google.setOnLoadCallback(OnLoad); //]]> </script> </head> <body> <div id="searchcontrol">Loading...</div> </body> </html> Now, what I'm desperately trying to do since 4-5 hours is to have the search results between the <div id="searchcontrol"></div> encoded as HTML in the loaded page. Currently, when the page is loaded and I look at the source code, I have the word 'Loading...' in the <div> tags, despite in the normal view there are G results listed. I need those results encoded as HTML for SEO reasons. Researching on this matter I thought the problem could be the OnLoad command, that makes the script load after all the other HTML elements are loaded. But I tried to make it load before all the elements in the page, and the problem persists. How can I solve this? Thanks in advance for any help! Hi, I am looking for an efficient way to go thru all the list items I have in an unordered page and change an attribute. I know I should be able to do it using getElementsByTagName, but I can't seem to get it all working. Can someone please point me in the right direction? Thanks, Thad Help will be greatly appreciated! Situation: I have a very long page divided into many sections vertical-wise marked by bookmarks, say pageX.html#s1 to s10. I need to show the section inside an iframe (iFrame1) on the mainpage (mainpage.html). I am thinking of having 4 buttons, sitting on the mainpage, to help navigate between these sections on pageX, namely NEXT, PREVIOUS, TOP, END. condition of the frame, fixed width/height, no scroll, no border. Very new to javascript but need this code to make a page work for BIZ. Thank you in advance for anyone kind enough to point the right direction! hi this is my code: <HTML> <HEAD> <script language="JavaScript"> function show(){ if (document.getElementById("menu2").style.visibility = "hidden") { document.getElementById("menu2").style.visibility = "visible"; } } function hide(){ document.getElementById("menu2").style.visibility = "hidden"; } </script> <style type="text/css"> #menu {position:absolute; left:0;top:0; z-Index:0;font-family:arial; font-size:14px; color:blue; visibility:visible} #menu2 {position:absolute; left:0;top:27; z-Index:0;font-family:arial; font-size:14px; color:blue; visibility:hidden} </style> </HEAD> <BODY> <div ID="menu" onmouseover="show()"> <table border="1" bgcolor="#FFCC00"><tr><td>File</td></tr></table> </div> <div ID="menu2" onmouseout="hide()"> <table border="1" bgcolor="#FFCC00"><tr><td>New</td></tr></table> </div> </BODY> </HTML> Now i want the second layer to appear when i hover over the first, which it does. however i want it so that when i move my cursor away from the second layer it dissapears but the problem is it doesn't seem to work. any help apreciated. thanks I had some help last week with a brands a to z list which shows a div containing list of brands starting with the relevant letter onclick. It works pretty well with one flaw. The brand links within the div seem to activate the toggle function. My wish is that the layer is shown when a letter is clicked but then hides on div onMouseOut so that a different letter can be selected. Here is by code; Javascript; Code: function toggle_visibility(o,id) { var obj = document.getElementById(id); obj.style.display=(obj.style.display == 'block')?'none':'block'; if (obj.style.display!='none') { obj.style.left=zxcPos(o)[0]+20+'px'; obj.style.top=zxcPos(o)[1]+20+'px';} } function zxcPos(obj){ var rtn=[0,0]; while(obj){ rtn[0]+=obj.offsetLeft; rtn[1]+=obj.offsetTop; obj=obj.offsetParent; } return rtn; } Here is a sample of my a to z table; Code: <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename20');">U</a></td> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename21');">V</a></td> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename22');">W</a></td> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename23');">X</a></td> </tr> <tr> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename24');">Y</a></td> <td align="center" class="LN-Brands-Alphabox"><a href="#" onclick="toggle_visibility(this,'uniquename25');">Z</a></td> </tr></table> And here is an example of the Brand name div ; Code: <div id="uniquename21" onMouseOut="toggle_visibility('null','uniquename21');" style="display:none; position:absolute; border-style: solid; background-color: white; padding: 5px;"> <a href="Manufacturer-view.asp?ManID=43">VPX</a><br> <a href="Manufacturer-view.asp?ManID=44">Vyomax</a> </div> You can view the site on my test page; http://www.dp-development.co.uk/ProteinStop/site/ (Brand menu on the left nav) Thank you for any help you can give I'm not sure why this code executes the first if condition. What should I be doing instead? <!DOCTYPE html> <head> <style> #test { visibility:hidden; } </style> <script type="text/javascript"> function read(ID) { if(document.getElementById(ID).style.visibility == '') alert("why does this pop up?"); else if(document.getElementById(ID).style.visibility == 'hidden') alert("this is what I would expect"); else alert("never reached"); } </script> </head> <body> <form><input type="button" value="test" onclick="read('test');""> <p id='test'> testing visibility</p> </body> </html> hi all, i have some code that is not registering. thinking i'm missing something obvious, but i sure can't see it. can someone else's eyes peruse this for me? thanks! code for the combo box: PHP Code: select name="country" size="1" id="country" style="position:absolute; left:451px; top:260px; width:176px; color:#00008B; font-family:Arial; font-weight:bold; font-size:13px; z-index:13" onChange="PhoneMask();"> <option value="1">United States</option> <option value="2">Australia</option> <option value="3">China</option> <option value="4">Mexico</option> <option value="5">United Kingdom</option> </select> code for the different labels i want to display: PHP Code: /*THIS SECTION IS FOR THE DIFFERENT PHONE NUMBERS OF THE VARIOUS COUNTRY CHOICES*/ <div id="phoneLabelUS" style="position:absolute; left:10px; top:225px; width:207px; height:15px;" align="left"> <font style="font-size:12px" color="#FF0000" face="Arial"><b> *Telephone Number </b></font><font style="font-size:12px" face="Arial"><b><span class="style9">(xxx-xxx-xxxx)</span> </b></font></div> <div id="phoneLabelAU" style="position:absolute; left:10px; top:225px; width:207px; height:15px; visibility: hidden;" align="left"><font style="font-size:12px" color="#FF0000" face="Arial"><b>*Telephone Number </b></font><font style="font-size:12px" face="Arial"><b><span class="style9"> (xx-xxxx-xxxx)</span></b></font></div> <div id="phoneLabelOTHER" style="position:absolute; left:10px; top:225px; width:207px; height:15px; visibility: hidden;" align="left"> <font style="font-size:12px" color="#FF0000" face="Arial"><b> Telephone Number</b></font></div> /*------------------------------------------------------------------------------------*/ here is my PhoneMask() function: PHP Code: function PhoneMask() { if (document.getElementById("country").value == "1") { document.getElementById("phoneLabelOTHER").style.zIndex = 50; document.getElementById("phoneLabelOTHER").style.visibility = 'hidden'; document.getElementById("phoneLabelAU").style.zIndex = 50; document.getElementById("phoneLabelAU").style.visibility = 'hidden'; document.getElementById("phoneLabelUS").style.zIndex = 51; document.getElementById("phoneLabelUS").style.visibility = 'visible'; } elseif (document.getElementById("country").value == "2") { document.getElementById("phoneLabelOTHER").style.zIndex = 50; document.getElementById("phoneLabelOTHER").style.visibility = 'hidden'; document.getElementById("phoneLabelAU").style.zIndex = 51; document.getElementById("phoneLabelAU").style.visibility = 'visible'; document.getElementById("phoneLabelUS").style.zIndex = 50; document.getElementById("phoneLabelUS").style.visibility = 'hidden'; } else { document.getElementById("phoneLabelOTHER").style.zIndex = 51; document.getElementById("phoneLabelOTHER").style.visibility = 'visible'; document.getElementById("phoneLabelAU").style.zIndex = 50; document.getElementById("phoneLabelAU").style.visibility = 'hidden'; document.getElementById("phoneLabelUS").style.zIndex = 50; document.getElementById("phoneLabelUS").style.visibility = 'hidden'; } } Hi there! I would REALLY appreciate any help! I've got a script that toggles the visibility of a div on "dashboard.html": Code: $(document).ready(function(){ $("#add_networks_wrapper, .remove_box").hide(); $(".toggle_add_networks").show(); $('.toggle_add_networks').click(function(){ $("#add_networks_wrapper, .remove_box").slideToggle(); }); }); On "dashboard.html" it works great. The div "add_networks_wrapper" is hidden until I click the link that toggles it. What I need is a link from a different html page (say "account.html" or whatever) to open "dashboard.html" with the hidden div's visible. Any help would be very appreciated! How can i change div visibility if for example index.php?site=news&show=angels http://mmwebstudio.eu/prace/2/ i have tryed to use: Quote: function MM_showHideLayers() { //v9.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible'v=='hide')?'hidden':v; } obj.visibility=v; } but i cannot use position absolute for my news( height of main div wont be spread) pls help I'm trying to implement a visibility on or off function for extra inputs when a radio button that is "yes" inside a table... it's so "Are you married?" "Yes" "No" (no is default checked) when you hit yes I want 3 more rows like a collapse or extend feature...within the same table. So basically what I want is the table to grow.. If you select "yes" then 3 more rows will be displayed that have other inputs available... do I need to construct these extra rows in javascript? or can I referance some html to do something? ..I'm just kinda lost and brain farted out today I think... any help much appreciated. Thanks! I am creating a website as part of a university project. as part of this i am trying to make a menu in the top right. after looking around i have found javascript top be the best way to do this. how would i go about making it so that when i click on one div (called map) a separate div (called mapMenu) visibility is toggled. thanks hi all, i am using this javascript code which i found on a random website to create a tooltip style popup. in my head is: Code: <script type="text/javascript"> function showmenu(elmnt) { document.getElementById(elmnt).style.visibility="visible" } function hidemenu(elmnt) { document.getElementById(elmnt).style.visibility="hidden" } </script> <style type="text/javascript"> #twittericon { position: fixed; bottom:148px; left: 6%; width: 33px; height:29px; z-index: 49; } #tweet{ position:fixed; bottom:178px; left: 3%; max-width:310px; color:#333333; font-family:Arial Narrow,Arial,Sans-serif; font-size:12px;; z-index:6000; visibility: hidden; } </style> in my body is: Code: <div id="twittericon" onMouseOver="showmenu('tweet')" onMouseOut="hidemenu('tweet')"> <a href="http://twitter.com/bubblejam" target="_blank"> <img src="http://nang-nang.net/tumblr/blog/twit-bird.gif" width="33" height="29" /></a> </div> <div id="tweet"> (latest tweet generating code) </div> this creates a little bird, which displays latest tweet when rolled-over. you can see a working example of this he http://nang-nang.net/tumblr/blog/try.html my question a (1) can i add something to the javascript to create a delay when onMouseOut so that the tweet doesn't disappear immediately? also (2) could i also add something to the javascript to create a visual effect when onMouseOver or onMouseOut occurs? like a fade in effect? or slide up effect? i've been playing around with scriptaculous effects but i'm not sure how to combine that script with my script above. an answer to (1) at least would be very much appreciated! I have a question: how can you use a drop down box to show another drop down box? Here is my code below. Code: <html> <head> <script type="text/javascript"> "use strict"; function showlist() { var list=document.getElementById("id1"); var newlist=list.options[list.selectedIndex].value; if (newlist==="Opt1") { document.getElementById("one").style.visibility="visible"; document.getElementById("two").style.visibility="hidden"; } if (newlist==="Opt2") { document.getElementById("two").style.visibility="visible"; document.getElementById("one").style.visibility="hidden"; } } </script> <style type="text/css"> select.a{visibility:hidden;} </style> </head> <body> <select id="chooseboxtoshow"> <option value="Opt1">Option 1</option> <option value="Opt2">Option 2</option> </select><br /> <select display="none" id="one" class="a"> <option value="1a">Option 1a</option> <option value="1b">Option 2a</option> </select><br /> <select display="none" id="two" class="a"> <option value="2a">Option 1b</option> <option value="2b">Option 2b</option> </select><br /> <input type="button" value="Show new list" onclick="showlist()"> </body> </html> Does anyone have ideas on how I can do it? Thanks! I have that image at the top of my website. What I want to do is have it be a link that toggles a div somewhere else on the board. I have been using this code: Code: <input type="checkbox" name="thebox" onclick="javascript:toggleDiv('block');">Toggle Block <div id="searchbock">*search form here, obviously*</div> <script language="javascript"> function toggleDiv(id) { var div = document.getElementById(id); var current = div.style.display; if (current == 'none') div.style.display = 'block'; else div.style.display = 'none'; } </script> But the checkbox is rather ugly and I would much rather use my custom image. Thoughts? I am making a framework to easily set up javascript tabs that toggle content. For example, the button "homeButton" toggles the "home" section. This is a fragment of my code and I am having two problems with it: Code: for (var i = 0 in tabs) { document.getElementById(tabs[i] + "Button").onclick = function() { hideAll(tabs); document.getElementById(tabs[i]).style.visibility = 'visible'; } } Problem number 1: Regardless of which button I click, it always registers as the last button. Problem number 2: The hideAll(tabs), another function in the program works, but Code: document.getElementById(tabs[i]).style.visibility = 'visible'; doesn't. I get left with a blank page. Any help is greatly appreciated. BTW when I use something like Code: document.getElementById(tabs[0]).style.visibility = 'visible'; outside of the for loop, it works fine. I'm quite stumped. Julian |