JavaScript - Trying To Get Switch To Work In Tabs
I am using a script I found and trying to make some changes.
It is a avatar creating script that will put a face together. The tabs are different parts of the face. The problem is I don't want all the different hair colors and styles to show and in the color tab when you click a color it will bring up the hair styles in that color only in the next tab. I have tried if(isset($_GET['color'])) { but this is only showing the first color style cant it to work. So then tried to use switch like this PHP Code: <p> <span name="color"> <img src="herotmb/color0.png" alt="" /><input name="avatar[color]" type="radio" value="black" id="black" onclick="swapImage(this);" /> <img src="herotmb/color1.png" alt="" /><input name="avatar[color]" type="radio" value="brown" id="brown" onclick="swapImage(this);" /> <img src="herotmb/color2.png" alt="" /><input name="avatar[color]" type="radio" value="darkbrown" id="darkbrown" onclick="swapImage(this);" /> <img src="herotmb/color3.png" alt="" /><input name="avatar[color]" type="radio" value="yellow" id="red" onclick="swapImage(this);" /> <img src="herotmb/color4.png" alt="" /><input name="avatar[color]" type="radio" value="red" id="yellow" onclick="swapImage(this);" /> </span> </p> <?php switch(id){ case 'BLACK': echo ' <p> <img src="heroimg/hair0-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; break; case 'BROWN': echo ' <p> <img src="herotmb/hair0-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-brown" /> <img src="herotmb/hair1-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-brown" /> <img src="herotmb/hair2-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-brown" /> <img src="herotmb/hair3-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-brown" /> <img src="herotmb/hair4-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-brown" /> <img src="herotmb/hairNone-brown.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; break; case 'DARKBROWN': echo ' <p> <img src="herotmb/hair0-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-darkbrown" /> <img src="herotmb/hair1-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-darkbrown" /> <img src="herotmb/hair2-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-darkbrown" /> <img src="herotmb/hair3-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-darkbrown" /> <img src="herotmb/hair4-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-darkbrown" /> <img src="herotmb/hairNone-darkbrown.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; break; case 'RED': echo ' <p> <img src="herotmb/hair0-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-red" /> <img src="herotmb/hair1-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-red" /> <img src="herotmb/hair2-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-red" /> <img src="herotmb/hair3-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-red" /> <img src="herotmb/hair4-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-red" /> <img src="herotmb/hairNone-red.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; break; case 'YELLOW': echo ' <p> <img src="herotmb/hair0-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-yellow" /> <img src="herotmb/hair1-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-yellow" /> <img src="herotmb/hair2-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-yellow" /> <img src="herotmb/hair3-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-yellow" /> <img src="herotmb/hair4-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-yellow" /> <img src="herotmb/hairNone-yellow.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; } ?> nothing shows up. I have searched and found this and tried it but get more errors because I'm not just using images Code: http://www.codingforums.com/showthread.php?t=205694 How can I get this to work ? Similar Tutorials" <body> <a href="biography.html" id="biography">BIO</a> <script type="text/javascript"> window.onload = initRedirect; function initRedirect() { switch(getElementById.onclick) { case "getElementById"biography".onclick": alert("Four score and seven years ago..."); return false; default: } } </script> </body> " I don't quite understand the getElementById property. Is there a way I can get it so that I click on the biography link and an alert displays? here's the code i've got to make some tabbed content on my website: Code: $(document).ready(function(){ $('#headingHome div').hide(); // Hide all divs $('#headingHome div:first').show(); // Show the first div $('.ticker_buttonP a:first').addClass('active'); // Set the class of the first link to active $('.ticker_buttonP a').click(function(){ //When any link is clicked $('.ticker_buttonP a').removeClass('active'); // Remove active class from all links $(this).addClass('active'); //Set clicked link class to active var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link $('#headingHome div').hide(); // Hide all divs $(currentTab).show(); // Show div with id equal to variable currentTab return false; }); }); and my html (all content removed for size's sake): Code: <div id="headingHome"> <div id="first"></div><!-- /first --> <div id="second"></div><!-- /second --> <div id="third"></div><!-- /third --> <div id="fourth"></div><!-- /fourth --> <div id="fifth"></div><!-- /fifth --> <p class="ticker_buttonP"> <a href="#first"></a> <a href="#second"></a> <a href="#third"></a> <a href="#fourth"></a> <a href="#fifth"></a> </p> </div><!-- /headingHome --> that works fine so far, however i want the content to fade in and out when the tabs change, and i also want the tabs to rotate automatically like seen on this site: http://www.sosfactory.com/ I'm new to this, and I cant find anything on the net about it that i can understand enough to put it together. could anyone help me, please? many thanks My switch function just goes to the default. I've double double checked the file paths of the image on the page and it's right. So I'm not sure what's going on. here's what I got: Code: function change2(picName,imgName) { switch (document[picName].src) { case document[picName].src= "images/leaf_shapes/leaf_auriculate.gif": document[picName].src = "images/leaf_shapes/crenate/leaf_elliptic_crenate.gif"; break; case document[picName].src= "images/leaf_shapes/leaf_cordate.gif": document[picName].src= "images/leaf_shapes/serrate/leaf_elliptic_serrate.gif"; break; default: document[picName].src= "images/leaf_shapes/transparent1.gif"; } } This is driving me crazy! So I'm using a javascript file to switch out items when a thumbnail is clicked. This includes photo, title, description, price, size, quantity and add to cart button.... The original code on the html file works fine, but as soon as it is swapped by onclick, the 'add to cart' button does nothing! Here is the code: Code: var addDisplay = document.getElementById('cart-add'); addDisplay.innerHTML = "<a class='item_add' href='/' onclick='simpleCart.add(); return false;'><img src='images/shop/cart-add.jpg' width='118' height='26' border='0'></a>"; that is what shows in my javascript file... here is what's on the html file: Code: <div id="cart-add"><a class='item_add' href='/' onclick='simpleCart.add(); return false;'><img src="images/shop/cart-add.jpg" width="118" height="26" border="0"></a> </div> and that adds the item to the cart just fine, but when a thumbnail is clicked on, activating the javascript file to switch out the item/elements, the 'add to cart' button no longer does anything... by the way, I am using simpleCart.js PLEASE HELP, PLEASE!? Please PM me if you need more info... or post here if you have a solution. Thanks! Hey everyone, I'm a newbie writing a tic tac toe program using OOP. It was simple setting it up so that a player could click on a box to put an X or an O there, but I've run into serious issues when trying to make it so a player couldn't overwrite the AI's choice and the AI couldn't overwrite the player's. An example of this would be if I made the top right box an X and the AI then made the center box an O, and then I accidentally clicked the center box and made it into an X. I want to prevent that. Every box on the grid is an object with the property of "taken" that helps the program know if a box is empty or not, so as to avert any overwriting in the first place. If the box is empty, this.taken = 0. If the box is filled by a player, taken = 1. If filled by AI, taken = 2. I made it matter whether it was AI or human so later i can check if one of them got tic tac toe. Anyway, by default the constructor class sets this.taken = 0. But the method for checking availability and writing the X or O uses a switch which checks if taken = 0. If it is, it sets taken to either 1 or 2 and writes the necessary symbol. If taken = 1 or 2, it just alerts the player that the spot is taken. But for some reason the switch statement can't tell when taken = anything other than 0. It always executes the code for 0 even though the code for 0 inherently makes it so that taken never equals 0 again, which means case 0 cannot happen anymore. Below is the code with notes. Code: function main(input){//start of main function// function Click(who, where, what){ //this is the method for checking if it's taken or not and writing the X or O if it isn't// /*the argument who represents a number. 0 is no one, 1 is human, 2 is AI; where is a string literal representing the spot on the grid*/ switch(this.taken){ case 0: this.taken = who; document.getElementById(where).innerHTML = what; break; case 1: alert("this spot is taken"); break; case 2: alert("this spot is taken"); }//end switch }//end Click function Box(inputhere){//start of class// this.taken = 0; this.pick = Click; } //end of Box class// //object declarations (I cut out most of them and left only the relevant ones// var topleft = new Box(); var topmid = new Box(); var topright = new Box(); var centerright = new Box(); //end of object declarations// switch (input){ /*in each .pick(), the first arg is whether or not a player chose it (1 = player did, 2 = comp did). The second arg is which box and the third is whether to put an X or O. The input variable in the switch statement is an argument passed through main() when the player clicks on a box. Topleft passes 1.1, topmid passes 1.2 and so on.*/ case 1.1:{ //The first instance of .pick() in each case is what the player did. The second is what the AI will do in repsonse.// topleft.pick(1, "topleft", "X"); topmid.pick(2, "topmid", "<span>O</span>"); break; }//end of case 1.1 case 1.3:{ topright.pick(1, "topright", "X"); centerright.pick(2, "centerright", "<span>O</span>"); break; }//end of case 1.3 }//end of switch }//end of main// Is there anyone who has any idea why on earth this is happening? I've been at it for an embarrassing amount of hours. Also, thanks to anyone who even considers helping : ) (feel free to flame me if my code sucks or my post is too long or anything). Hey guys, No clue what the code is for this. I did try creating one but it dramaticly failed. Just wondering what is the code for a box with tabs where if you click the tabs it provides information i the box below. and does not link you to a site. And i need 6 tabs on it. Thanks for people that can provide.
I am having a problem with a page I am building using jquery tabs. I have basically put a set of tabs within another set. The top level of tab navigation works fine, but then you click on the tabs navigation within the first tab it doesnt work. http://dl.dropbox.com/u/14080718/Final/TabsInTabs.html I cant get it to work and not sure why. I am still learning web design and I am not sure if this is a html/css or jquery problem. I would appreciate any help anyone wants to give. Thanks, Good Afternoon, I am new to coding and I am needing help coding a form. I need javascript coding that will give me tabs. I also need the tabs to be greyed out for the users who should not see those tabs. So if i have an analyst, section chief and division chief. I need three tabs. when the analyst is logged in filling out their questions on the form i want the sections cheif and division chief tabs to be greyed out. Can anyone help me with this! Lizz Reply With Quote 12-17-2014, 07:34 PM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts what do you have so far? Dear friends, I use this script wich works fine in FF, Opera and Chrome but not in IE! Code: <script type="text/javascript"> function DoAllThese() { window.open('http://google.com', 'One','_blank'); window.open('http://www.yahoo.com','Two','_blank'); } </script> Code: <button onClick="DoAllThese();">Open</button> Is it possible to do it in IE? Hello, It is my first post here so hello everybody I am currently building a website and it is the first time I have experimented with ajax, jquery etc etc so forgive me if I come across as a bit of novice in all this but ......... I am. lol I have a column of links that use ajax to load content into the adjacent DIV, and I have used the loadobs function to load the JS and CSS files along with the external file. Now within the external file I have used javascript to create a 3 tab section; when you first load the page it is fine BUT if you navigate away from the page and then try going back and loading the same external page then the tabs stop working and all the content of the tabbed sections stack ontop of one another as though the javacript isnt working? I am completely new to javascript but I think it is fabulous and I am keen to learn the ins and outs and would be really greatful if someone who knows what they are doing could point me in the direction of where I am going wrong or maybe what part of the code could be causing the error. It is a work in progress but the page I am having the problems on can be found at http://www.hm-designs.co.uk/crossland/solo.php if you click on the top link in the left hand column called Tara - Female vocalist you will be able to see where the tabs are. Thank you in advance if anyone may be able to help me Kind Regards, Helen Hi, I have a problem with my script displaying tabs (jquery tabs) in frames. When the scripts (not in frames) are viewed in the browser, the tabs are displayed correctly. I created a script containing frames for existing scripts to be displayed in certain frames. Some scripts display fine in the frames, even some of those that contain tabs. While some may display correctly, I still get some scripts when viewed in the frames script that are not displaying the tabs correctly. Can anyone please give me a solution to this problem. Thank you. Hi, I have created three tabs to display different content in each. Although I can click and go to the specific tab, but except the first 1 the other two tabs don't display any content or html that I have. Can anyone find any problem in the code? I have attached just the html. please excuse the structure of the code as it needs to be that way. thanks I am having some problems with some JS code that does not work cross browsers Here is my code Code: <html> <head> <link rel="STYLESHEET" type="text/css" href="../../include/css/tab.css"> <script src="../../include/js/tabpane.js" type="text/javascript"></script> </head> <body> <div name="objBody"> <div id="tabpane"> <div> <h2>Contact</h2> <div> <br>THIS IS CONTACTS TEXT </div> </div> <div> <h2>Contact2</h2> <div> <br>THIS IS CONTACTS TEXT2222 </div> </div> </div> </div> <script type="text/javascript"> var tp = new TabPane(document.getElementById("tabpane")); </script> </body> </html> CSS Code: .tab_pane_holder { width: 100%; background-color: #336699; font-family: verdana; font-size: 8pt; border-right: 1px solid black; border-left: 1px solid black; border-top: 1px solid black; } .tab_normal { border-right: 1px solid black; border-left: 1px solid white; border-bottom: 1px solid black; border-top: 1px solid white; padding: 5px; background-color: #5a7edc; text-align: center; /*width: 100px;*/ height: 10px; color: white; } .tab_active { border-right: 1px solid black; border-left: 1px solid black; border-top: 1px solid black; background-color: white; padding: 5px; text-align: center; /*width: 100px;*/ height: 10px; color: black; } .tab_after_active { border-right: 1px solid black; border-left: 0px solid black; border-top: 1px solid white; border-bottom: 1px solid black; background-color: #5a7edc; padding: 5px; text-align: center; /*width: 100px;*/ height: 10px; color: white; } .tab_before_active { border-left: 1px solid white; border-bottom: 1px solid black; background-color: #5a7edc; border-top: 1px solid white; text-align: center; padding: 5px; /*width: 100px;*/ height: 10px; color: white; } JS Code: function TabPane(el) { var tmp = this; this.element = el; this.tabs = new Array(); this.divs = new Array(); this.selected = null; for(var i = 0; i < el.childNodes.length; i++) { this.tabs[i] = this.element.childNodes[i].childNodes[0].innerHTML; } for(var i = 0; i < this.element.childNodes.length; i++) { this.divs[i] = this.element.childNodes[i]; } for(var i = 0; i < this.element.childNodes.length; i++) { this.element.childNodes[i].removeChild(this.element.childNodes[i].childNodes[0]); } this.tabPane = document.createElement("div"); this.element.insertBefore(this.tabPane,this.element.childNodes[0]); this.tabPane.className = "tab_pane_holder"; for(var i = 0; i < this.tabs.length; i++) { var x = this.tabs[i]; this.tabs[i] = document.createElement("span"); this.tabPane.appendChild(this.tabs[i]); this.tabs[i].innerHTML = x; this.tabs[i].className = "tab_normal"; this.tabs[i].style.cursor = "hand"; this.tabs[i].onselectstart = function() { return false; } this.tabs[i].onclick = function() { tmp.showPage(this); } } for(var i = 0; i < this.divs.length; i++) { this.divs[i].style.display = "none"; this.divs[i].style.width = this.element.style.width; this.divs[i].style.height = this.element.style.height; this.divs[i].style.overflow = "auto"; this.divs[i].style.borderRight = "1px solid black"; this.divs[i].style.borderBottom = "1px solid black"; this.divs[i].style.borderLeft = "1px solid black"; } this.showPage = function(el) { var x,y; for(var i = 0; i < this.tabs.length; i++) { if(el == this.tabs[i]) { x = i; } } y = ((x-1) < 0)?0:(x-1); for(var i = 0; i < this.tabs.length; i++) { this.tabs[i].className = "tab_normal"; } this.tabs[y].className = (y == x)?"tab_active":"tab_before_active"; if(this.tabs[y+1]) { this.tabs[y+1].className = (y == x)?"tab_after_active":"tab_active"; } if(this.tabs[y+2]) { this.tabs[y+2].className = (y == x)?this.tabs[y+2].className:"tab_after_active"; } if(x == 0) { this.tabs[x].style.borderLeft = "0px solid black"; } for(var i = 0; i < this.divs.length; i++) { var show = (i == x)?"block":"none"; this.divs[i].style.display = show; } } this.showPage(this.tabs[0]) } I am using this JQuery tabbed viewer - http://flowplayer.org/tools/demos/tabs/skin4.htm on my home page: http://billboardfamily.com/?theme=DeepFocus The issue I am having is that the content on the "Photos" tab is not showing at all. In the "Blog" tab, I am calling some PHP code & it works fine, so that should be the case with the code called in the "Photos" tab, as well, but it's not working. Can anyone help me figure out why? Here is the source code for my home page (the tabbed area) Code: <!-- BEGIN main blog content --> <?php $lastposts = get_posts('numberposts=1&category=15'); foreach($lastposts as $post) : setup_postdata($post); ?> <div id="mainblog" style="margin-top: 15px;"> <div class="mainblog-content"> <?php endforeach; ?> </div> <!-- start tabs--> <div id="panes"> <div> <p> <h2 style="color:#000000;"><a style="color:#000000;" href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2> <?php the_content(); ?> It is 515 feet tall with 38 stories. Severud Associates were the structural engineering consultants. It stands as one of the finest examples of the functionalist aesthetic and a masterpiece of corporate modernism. It was designed as the headquarters for the Canadian distillers Joseph E. Seagram's & Sons, thanks to the foresight of Phyllis Lambert, the daughter of Samuel Bronfman, Seagram's CEO. </p> </div> <div> <p> <div id="portfolio-items" class="clearfix"> <?php $allCats = get_categories(); $blogCats = array(); $blogcat = get_cat_ID(get_option('deepfocus_blog_cat')); foreach ($allCats as $category) { if (in_subcat($blogcat, $category->cat_ID)) $blogCats[] = $category->cat_ID; } $args = array('category__not_in' => $blogCats, 'showposts' => get_option('deepfocus_portfolio_number')); $i = 1; query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); ?> <?php include(TEMPLATEPATH . '/includes/gallery.php'); ?> <?php $i++; endwhile; endif; wp_reset_query(); ?> <div class="clear"></div> <a href="<?php echo(get_category_link(get_cat_ID(get_option('deepfocus_portfolio_cat')))); ?>" class="readmore entergallery"><span><?php _e('Enter The Gallery','DeepFocus'); ?></span></a> </div> <!-- end #portfolio-items --> </p> </div> <div> <p> Contests & Specials use custom fields </p> </div> <div> <p> Connect on Facebook, etc use custom fields </p> </div> <div> <p> Comments </p> </div> <div> <p> <a href="http:www.billboardfamily.com/rss">Subscribe To Our Blog</a> <br />Also, add mailing list here </p> </div> <div class="clearfix"></div> </div> <br clear="all" /> <!-- navigator --> <div id="nav"> <ul> <li class="button-1"> <a href="#1"> <img src="http://farm4.static.flickr.com/3278/2691545308_e7e817afb0_s.jpg"/> <strong>Blog</strong> </a> </li> <li> <a href="#2"> <img src="http://farm4.static.flickr.com/3278/2691545308_e7e817afb0_s.jpg"/> <strong>Photos</strong> </a> </li> <li> <a href="#3"> <img src="http://farm1.static.flickr.com/3624/3323893148_8318838fbd_s.jpg"/> <strong>Contests & Specials</strong> </a> </li> <li> <a href="#4"> <img src="http://farm1.static.flickr.com/40/122343298_22333fb8e3_s.jpg" /> <strong>Connect</strong> </a> </li> <li> <a href="#5"> <img src="http://farm4.static.flickr.com/3278/2691545308_e7e817afb0_s.jpg"/> <strong>Comments</strong> </a> </li> <li> <a href="#6"> <img src="http://farm4.static.flickr.com/3278/2691545308_e7e817afb0_s.jpg"/> <strong>Subscribe</strong> </a> </li> </ul> </div> <br clear="all" /> <!-- end tabs--> <!-- END main blog content --> The same code is used below the tabs, and it works there....so it has something to do with the tabs. Please help. thanks I have a script that brings up an overlay box onclick that needs to be on top of everything else on page, however I can't get it to show on top of the navigation tabs. I tried calling the overlay script at the very beginning of the head section as well as tried to call it at the end but it doesn't seem to matter. Is there something I can add to the script to force it on top of every other object on the page? hi i try this code it not working beacause its open after one second open new tab javascript query but i have also use php redirect url also . i want javascript new tab url open new tab before page redriect here is code Code: <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { setTimeout(function() { window.open( 'https://google.com', '_blank' ); }, 2000); }); </script> <?php $url='http://yahoo.com'; echo header ('Location:'.$url); ?> in above code i want page redirect to yahoo.com before open new tab of google.com how to set it please help me hie everyone plz i want to know how to make tabs using javascript.... i want to make tabs like this website http://traveline.idea-sys.net/CSP/Default.aspx?A=2&P=50 --> (M/S Darakum - Description / GalleryDeck / Plan) can anyone help me plz? hi experts, I need to open same url (flash streaming site) on multiple tabs (min 100 tabs) without crashing my browser or drinking all my cpu usage. Pls dont ask me why i need to open like that. The question is can it be done. Thanks |