Search Results

Search found 668 results on 27 pages for 'addclass'.

Page 2/27 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Changing class of h2 inside specific div

    - by user1985060
    I want to make it so that everytime you click on an 'h2' tag, the 'input' inside gets selected and the 'h2' tag changes background, but if another 'h2' tag is clicked, the current highlight and 'input' selection changes accordingly. problem is that I have 3 different that do the same and with my code all the 3 forms are affected rather one. How do i limit my changes to only be contained to that form. Here is some code for clarification ' <form> ... <h2 onclick="document.getElementById(1001).checked='True' $('h2').removeClass('selected'); $(this).addClass('selected'); "> CONTENT <input type="radio" name="radio" id="1001" value="1001" /> </h2> ... </form>

    Read the article

  • Javascript function to add class to a list element based on # in url.

    - by Jason
    I am trying to create a javascript function to add and remove a class to a list element based on the #tag at the end of the url on a page. The page has several different states, each with a different # in the url. I am currently using this script to change the style of a given element based on the # in the url when the user first loads the page, however if the user navigates to a different section of the page the style added on the page load stays, I would like it to change. <script type="text/javascript"> var hash=location.hash.substring(1); if (hash == 'strategy'){ document.getElementById('strategy_link').style.backgroundPosition ="-50px"; } if (hash == 'branding'){ document.getElementById('branding_link').style.backgroundPosition ="-50px"; } if (hash == 'marketing'){ document.getElementById('marketing_link').style.backgroundPosition ="-50px"; } if (hash == 'media'){ document.getElementById('media_link').style.backgroundPosition ="-50px"; } if (hash == 'management'){ document.getElementById('mangement_link').style.backgroundPosition ="-50px"; } if (hash == ''){ document.getElementById('shop1').style.display ="block"; } </script> Additionally, I am using a function to change the class of the element onClick, but when a user comes to a specific # on the page directly from another page and then clicks to a different location, two elements appear active. <script type="text/javascript"> function selectInList(obj) { $("#circularMenu").children("li").removeClass("highlight"); $(obj).addClass("highlight"); } </script> You can see this here: http://www.perksconsulting.com/dev/capabilities.php#branding Thanks.

    Read the article

  • Jquery hasClass conditional not working

    - by Wade D Ouellet
    Hey, I have my site going here: http://www.treethink.com I am trying to make it so when a navigation item is clicked, it retracts the news ticker on the right and then doesn't run any of the extracting/timer functions anymore. I got it to retract but it still extracts. How I am doing it is I am adding a "noTicker" class with the nav buttons and removing it with colorbox's close button. The function runs on the page initially and if there isn't a "noTicker" class it runs the news ticker as planned. When a nav or close button is clicked it runs the function again which checks again to see if it has that class. So if it has the class it should retract (which it is so that must mean it's adding the class properly) and then not run any of the timer functions, but it still runs the timer functions for some reason. Here is my jQuery. /* Initially hide all news items */ $('#ticker1').hide(); $('#ticker2').hide(); $('#ticker3').hide(); var randomNum = Math.floor(Math.random()*3); /* Pick random number */ newsTicker(); function newsTicker() { if (!$("#ticker").hasClass("noTicker")) { $("#ticker").oneTime(2000,function(i) { /* Do the first pull out once */ $('div#ticker div:eq(' + randomNum + ')').show(); /* Select div with random number */ $("#ticker").animate({right: "0"}, {duration: 800 }); /* Pull out ticker with random div */ }); $("#ticker").oneTime(15000,function(i) { /* Do the first retract once */ $("#ticker").animate({right: "-450"}, {duration: 800}); /* Retract ticker */ $("#ticker").oneTime(1000,function(i) { /* Afterwards */ $('div#ticker div:eq(' + (randomNum) + ')').hide(); /* Hide that div */ }); }); $("#ticker").everyTime(16500,function(i) { /* Everytime timer gets to certain point */ /* Show next div */ randomNum = (randomNum+1)%3; $('div#ticker div:eq(' + (randomNum) + ')').show(); $("#ticker").animate({right: "0"}, {duration: 800}); /* Pull out right away */ $("#ticker").oneTime(15000,function(i) { /* Afterwards */ $("#ticker").animate({right: "-450"}, {duration: 800});/* Retract ticker */ }); $("#ticker").oneTime(16000,function(i) { /* Afterwards */ /* Hide all divs */ $('#ticker1').hide(); $('#ticker2').hide(); $('#ticker3').hide(); }); }); } else { $("#ticker").animate({right: "-450"}, {duration: 800}); /* Retract ticker */ $("#ticker").oneTime(1000,function(i) { /* Afterwards */ $('div#ticker div:eq(' + (randomNum) + ')').hide(); /* Hide that div */ }); } } /* when nav item is clicked re-run news ticker function but give it new class to prevent activity */ $("#nav li").click(function() { $("#ticker").addClass("noTicker"); newsTicker(); }); /* when close button is clicked re-run news ticker function but take away new class so activity can start again */ $("#cboxClose").click(function() { $("#ticker").removeClass("noTicker"); newsTicker(); }); Thanks, Wade

    Read the article

  • how to loop through menu and remove class and then add class to current menu item

    - by Jonathan Lyon
    Hi all I have this menu structure that is used to navigate through content slider panels. <div id="menu"> <ul> <li><a href="#1" class="cross-link highlight">Bliss Fine Foods</a></li> <li><a href="#2" class="cross-link">Menus</a></li> <li><a href="#3" class="cross-link">Wines</a></li> <li><a href="#4" class="cross-link">News</a></li> <li><a href="#5" class="cross-link">Contact Us</a></li> </ul> </div> I would like to loop through these elements and remove the highlight class and then add the highlight class to the current / last clicked menu item. Any ideas? Any help would be greatly appreciated. Thanks Jonathan

    Read the article

  • Remove second class from an element and add another class

    - by rahul
    Hi, $(document).ready ( function () { $(".MenuItem").mouseover ( function () { // Remove second class and add another class [ Maintain MenuItem class ] // Eg: For div1 remove Sprite1 and then add Sprite1Dis and for div2 // remove Sprite2 and add Spprite2Dis }); $(".MenuItem").mouseout ( function () { // Reverse of mouseover. ie Remove Sprite1Dis and add Sprite1 }); }); <div id="div1" class="MenuItem Sprite1"> &nbsp; </div> <div id="div2" class="MenuItem Sprite2"> &nbsp; </div> <div id="div3" class="MenuItem Sprite3"> &nbsp; </div> <div id="div4" class="MenuItem Sprite4"> &nbsp; </div> <div id="div5" class="MenuItem Sprite5"> &nbsp; </div> <div id="div6" class="MenuItem Sprite6"> &nbsp; </div> My problem is listed as comment inside the code section. What will be the easiest way to achieve this? Thanks in advance

    Read the article

  • How to add a class to just upper element of trigger with Jquery?

    - by Ahmet Kemal
    Hello, I am working on a Jquery accordion stuff. I want to add a class to the div that contains the accordion trigger <a> tag. You can look at my code. I want to add "first" class name to just first "newsitems" class when clicked "Recession fashion in Japan Video" title. <!-- news items starts--> <div class="newsitems"> <h3 class="business"> <a href="#" title="expand"><img src="images/expand_icon.gif" alt="collapse" class="collpase" /> Recession fashion in Japan Video</a> </h3> <p class="timestamp">0100hrs</p> </div> <!-- news items ends--> <!-- news items starts--> <div class="newsitems"> <h3 class="sports"> <a href="#" title="expand"><img src="images/expand_icon.gif" alt="collapse" class="collpase" /> Murray survives five-set thriller at Wimbledon</a> </h3> <p class="timestamp">0100hrs</p> </div> <!-- news items ends-->

    Read the article

  • jquery: adding class on to list-items only on mouseover-remove on mouse-out?

    - by user239831
    hey guys, what's the best way to do that: i have a list <ul> <li>hello</li> <li>good bye</li> <li>arrivederci</li> <li class="selected">dude</li> <li>whatever</li> </ul> Initially one item already has a class of .selected applied. When i hover over one of the list-items i want this one to have the .selected class. So every item should only have the class applied when im over, as soon as i leave the item the class get's removed and the next one has the class.

    Read the article

  • Help me to simplify my jQuery, it's growing huge and redundant!

    - by liquilife
    Hey all, I am no jQuery expert, but I'm learning. I'm using a bit (growing to a LOT) of jQuery to hide some images and show a single image when a thumb is clicked. While this bit of jQuery works, it's horribly inefficient but I am unsure of how to simplify this to something that works on more of a universal level. <script> $(document).ready(function () { // Changing the Materials $("a#shirtred").click(function () { $("#selectMaterials img").removeClass("visible"); $("img.selectShirtRed").addClass("visible"); }); $("a#shirtgrey").click(function () { $("#selectMaterials img").removeClass("visible"); $("img.selectShirtGrey").addClass("visible"); }); $("a#shirtgreen").click(function () { $("#selectMaterials img").removeClass("visible"); $("img.selectShirtGreen").addClass("visible"); }); $("a#shirtblue").click(function () { $("#selectMaterials img").removeClass("visible"); $("img.selectShirtBlue").addClass("visible"); }); // Changing the Collars $("a#collarred").click(function () { $("#selectCollar img").removeClass("visible"); $("img.selectCollarRed").addClass("visible"); }); $("a#collargrey").click(function () { $("#selectCollar img").removeClass("visible"); $("img.selectCollarGrey").addClass("visible"); }); $("a#collargreen").click(function () { $("#selectCollar img").removeClass("visible"); $("img.selectCollarGreen").addClass("visible"); }); $("a#collarblue").click(function () { $("#selectCollar img").removeClass("visible"); $("img.selectCollarBlue").addClass("visible"); }); // Changing the Cuffs $("a#cuffred").click(function () { $("#selectCuff img").removeClass("visible"); $("img.selectCuffRed").addClass("visible"); }); $("a#cuffgrey").click(function () { $("#selectCuff img").removeClass("visible"); $("img.selectCuffGrey").addClass("visible"); }); $("a#cuffblue").click(function () { $("#selectCuff img").removeClass("visible"); $("img.selectCuffBlue").addClass("visible"); }); $("a#cuffgreen").click(function () { $("#selectCuff img").removeClass("visible"); $("img.selectCuffGreen").addClass("visible"); }); // Changing the Pockets $("a#pocketred").click(function () { $("#selectPocket img").removeClass("visible"); $("img.selectPocketRed").addClass("visible"); }); $("a#pocketgrey").click(function () { $("#selectPocket img").removeClass("visible"); $("img.selectPocketGrey").addClass("visible"); }); $("a#pocketblue").click(function () { $("#selectPocket img").removeClass("visible"); $("img.selectPocketBlue").addClass("visible"); }); $("a#pocketgreen").click(function () { $("#selectPocket img").removeClass("visible"); $("img.selectPocketGreen").addClass("visible"); }); }); </scrip> <!-- Thumbnails which can be clicked on to toggle the larger preview image --> <div class="materials"> <a href="javascript:;" id="shirtgrey"><img src="/grey_shirt.png" height="122" width="122" /></a> <a href="javascript:;" id="shirtred"><img src="red_shirt.png" height="122" width="122" /></a> <a href="javascript:;" id="shirtblue"><img src="hblue_shirt.png" height="122" width="122" /></a> <a href="javascript:;" id="shirtgreen"><img src="green_shirt.png" height="122" width="122" /></a> </div> <div class="collars"> <a href="javascript:;" id="collargrey"><img src="grey_collar.png" height="122" width="122" /></a> <a href="javascript:;" id="collarred"><img src="red_collar.png" height="122" width="122" /></a> <a href="javascript:;" id="collarblue"><img src="blue_collar.png" height="122" width="122" /></a> <a href="javascript:;" id="collargreen"><img src="green_collar.png" height="122" width="122" /></a> </div> <div class="cuffs"> <a href="javascript:;" id="cuffgrey"><img src="grey_cuff.png" height="122" width="122" /></a> <a href="javascript:;" id="cuffred"><img src="red_cuff.png" height="122" width="122" /></a> <a href="javascript:;" id="cuffblue"><img src="blue_cuff.png" height="122" width="122" /></a> <a href="javascript:;" id="cuffgreen"><img src="/green_cuff.png" height="122" width="122" /></a> </div> <div class="pockets"> <a href="javascript:;" id="pocketgrey"><img src="grey_pocket.png" height="122" width="122" /></a> <a href="javascript:;" id="pocketred"><img src=".png" height="122" width="122" /></a> <a href="javascript:;" id="pocketblue"><img src="blue_pocket.png" height="122" width="122" /></a> <a href="javascript:;" id="pocketgreen"><img src="green_pocket.png" height="122" width="122" /></a> </div> <!-- The larger images where one from each set should be viewable at one time, triggered by the thumb clicked above --> <div class="selectionimg"> <div id="selectShirt"> <img src="grey_shirt.png" height="250" width="250" class="selectShirtGrey show" /> <img src="red_shirt.png" height="250" width="250" class="selectShirtRed hide" /> <img src="blue_shirt.png" height="250" width="250" class="selectShirtBlue hide" /> <img src="green_shirt.png" height="250" width="250" class="selectShirtGreen hide" /> </div> <div id="selectCollar"> <img src="grey_collar.png" height="250" width="250" class="selectCollarGrey show" /> <img src="red_collar.png" height="250" width="250" class="selectCollarRed hide" /> <img src="blue_collar.png" height="250" width="250" class="selectCollarBlue hide" /> <img src="green_collar.png" height="250" width="250" class="selectCollarGreen hide" /> </div> <div id="selectCuff"> <img src="grey_cuff.png" height="250" width="250" class="selectCuffGrey show" /> <img src="red_cuff.png" height="250" width="250" class="selectCuffRed hide" /> <img src="blue_cuff.png" height="250" width="250" class="selectCuffBlue hide" /> <img src="green_cuff.png" height="250" width="250" class="selectCuffGreen hide" /> </div> <div id="selectPocket"> <img src="grey_pocket.png" height="250" width="250" class="selectPocketGrey show" /> <img src="hred_pocket.png" height="250" width="250" class="selectPocketRed hide" /> <img src="blue_pocket.png" height="250" width="250" class="selectPocketBlue hide" /> <img src="green_pocket.png" height="250" width="250" class="selectPocketGreen hide" /> </div> </div>

    Read the article

  • Adding active class in menu only works on first page

    - by rileychuggins
    I have nav links that become active once they come into the window. I need to implement this on three separate pages on my website but the following scripts only work for the first page. var services_refresh = function () { // do stuff console.log('Stopped Scrolling'); if($('#ct_scans.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#ct_scans"]').addClass('active'); } else if($('#xray.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#xray"]').addClass('active'); } else if($('#fluoroscopy.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#fluoroscopy"]').addClass('active'); } else if($('#mri.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#mri"]').addClass('active'); } else if($('#neuroimaging.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#neuroimaging"]').addClass('active'); } else if($('#nuclear_medicine.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#nuclear_medicine"]').addClass('active'); } else if($('#ultrasound.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#ultrasound"]').addClass('active'); } else if($('#mammography.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#mammography"]').addClass('active'); } else if($('#breast_ultrasound.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#breast_ultrasound"]').addClass('active'); } else if($('#breast_biopsy.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#breast_biopsy"]').addClass('active'); } else if($('#breast_mri.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#breast_mri"]').addClass('active'); } else if($('#osteoporosis.anchor').visible()) { $('#our_services_sub_sections li a').removeClass('active'); $('#our_services_sub_sections li a[href="#osteoporosis"]').addClass('active'); } }; Here is my HTML for the first page that works: <ul id="our_services_sub_sections" class="diagnostic_images"> <li><a class="scroll active" href="#ct_scans">CT Scans</a></li> <li><a class="scroll" href="#xray">X-Ray</a></li> <li><a class="scroll" href="#fluoroscopy">Fluoroscopy</a></li> <li><a class="scroll" href="#mri">MRI</a></li> <li><a class="scroll" href="#neuroimaging">Neuroimaging</a></li> <li><a class="scroll" href="#nuclear_medicine">Nuclear Medicine</a></li> <li><a class="scroll" href="#ultrasound">Ultrasound</a></li> </ul> Here is my HTML for the second page which does not work: <ul id="our_services_sub_sections" class="womens_imaging"> <li><a class="scroll active" href="#mammography">Mammography</a></li> <li><a class="scroll" href="#breast_ultrasound">Breast Ultrasound</a></li> <li><a class="scroll" href="#breast_biopsy">Breast Biopsy</a></li> <li><a class="scroll" href="#breast_mri">Breast MRI</a></li> <li><a class="scroll osteo" href="#osteoporosis">Osteoporosis<br />Evaluation (DEXA)</a></li> </ul> Why is this not working?

    Read the article

  • jQuery script works in Firefox but not in IE. Why am I not surprised?

    - by Ben Tew
    I'm working with the context of a CMS system and trying to turn seperate div's into tabs. You can see it at http://www.wtvynews4.com/test I've kludged together some code from a tutorial site. <script charset="utf-8" type="text/javascript"> jQuery(function() { //When page loads... $("div[ondblclick$='87119417']").attr("id", "87119417"); $("div[ondblclick$='87119482']").attr("id", "87119482"); $("div[ondblclick$='87119672']").attr("id", "87119672"); $("div[ondblclick$='87119727']").attr("id", "87119727"); $("div[ondblclick$='87119812']").attr("id", "87119812"); $("div[ondblclick$='87119417']").addClass("tab_content"); $("div[ondblclick$='87119482']").addClass("tab_content"); $("div[ondblclick$='87119672']").addClass("tab_content"); $("div[ondblclick$='87119727']").addClass("tab_content"); $("div[ondblclick$='87119812']").addClass("tab_content"); $(".tab_content").hide(); //Hide all content $("ul.morenewstabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab content //On Click Event $("ul.morenewstabs li").click(function() { $("ul.morenewstabs li").removeClass("active"); //Remove any "active" class $(this).addClass("active"); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content $(activeTab).show(); //Fade in the active ID content return false; }); }); </script> Everything works fine in Firefox but not IE. can you provide any assistance? When the page loads the attribute ID's and classes aren't assigned. I tried changing jQuery(function() { to $(document).ready(function() still no luck.

    Read the article

  • Combobox item style

    - by user373721
    my project is asp.net MVC, using Telerik MVC combobox. I can change the sytle of the first item if I use: var item = combobox.dropDown.$items.first(); item.addClass('test'); Or change all items, using: combobox.dropDown.$items.addClass('test'); But I need to change just specific items (based on a model), I tried: combobox.dropDown.$items[1].addClass('test'); I get this error: Object doesn't support property or method 'addClass'

    Read the article

  • I get an `Cannot read property 'slice' of undefined` message when I use the scrollTo jQuery plugin inside this function

    - by alexchenco
    I'm using the jQuery scrollTo plugin. I get this error in my JS Console: 16827Uncaught TypeError: Cannot read property 'slice' of undefined d.fn.scrollToindex.html.js:16827 jQuery.extend.eachindex.html.js:662 d.fn.scrollToindex.html.js:16827 jQuery.extend.eachindex.html.js:662 jQuery.fn.jQuery.eachindex.html.js:276 d.fn.scrollToindex.html.js:16827 popupPlaceindex.html.js:18034 (anonymous function)index.html.js:17745 jQuery.extend._Deferred.deferred.resolveWithindex.html.js:1018 doneindex.html.js:7247 jQuery.ajaxTransport.send.script.onload.script.onreadystatechange When I place $(".menu").scrollTo( $("li.matched").attr("id"), 800 ); inside it. function popupPlace(dict) { $popup = $('div#dish-popup'); $popup.render(dict,window.dishPopupTemplate); if(typeof(dict.dish) === 'undefined') { $popup.addClass('place-only'); } else { $popup.removeClass('place-only'); } var $place = $('div#dish-popup div.place'); var place_id = dict.place._id; if(liked[place_id]) { $place.addClass('liked'); } else { $place.removeClass('liked'); } if(dict.place.likes) { $place.addClass('has-likes'); } else { $place.addClass('zero-likes'); } var tokens = window.currentSearchTermTokens; var tokenRegex = tokens && new RegExp($.map(tokens, RegExp.escape).join('|'), 'gi'); $.each(dict.place.products, function(n, product) { $product = $('#menu-item-'+product.id); if(liked[place_id+'/'+product.id]) { $product.addClass('liked'); } if(tokens && matchesDish(product, tokens)) { $product.addClass('matched'); $product.highlight(tokenRegex); } else { $product.removeClass('matched'); $product.removeHighlight(); } if(product.likes) { $product.addClass('has-likes'); } else { $product.addClass('zero-likes'); } }); $('#overlay').show(); $('#dish-popup-container').show(); // Scroll to matched dish //$("a#scrolll").attr("href", "#" + $("li.matched").attr("id")); //$("a#scrolll").attr("href", "#" + $("li.matched").attr("id")); //$("a#scrolll").trigger("click"); $(".menu").scrollTo( $("li.matched").attr("id"), 800 ); // Hide dish results on mobile devices to prevent having a blank space at the bottom of the site if (Modernizr.mq('only screen and (max-width: 640px)')) { $('ol.results').hide(); } $(".close-dish-popup").click(function() { $("#overlay").hide(); $("#dish-popup-container").hide(); $('ol.results').show(); changeState({}, ['dish', 'place', 'serp']); }); showPopupMap(dict.place, "dish-popup-map"); } Any suggestion to fix this?

    Read the article

  • jQuery multiple if else Statements

    - by Chris MMgr
    I have a set of images that I am trying to activate (change opacity) based on the position of a user's window. The below code works, but only through a long series of if else statements. Is there a way to shorten the below code? //Function to activate and deactivate the buttons on the side menu function navIndicator() { var winNow = $(window).scrollTop(); var posRoi = $('#roi').offset(); var posRoiNow = posRoi.top; //Activate the propper button corresponding to what section the user is viewing if (winNow == posRoiNow * 0) { $('#homeBut a img.active').stop().animate({ opacity: 1 } { queue: false, duration: 300, easing: "easeOutExpo" }); $('#homeBut').addClass("viewing") } else { $('#homeBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#homeBut').removeClass("viewing") } if (winNow == posRoiNow) { $('#roiBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#roiBut').addClass("viewing") } else { $('#roiBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#roiBut').removeClass("viewing") } if (winNow == posRoiNow * 2) { $('#dmsBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#dmsBut').addClass("viewing") } else { $('#dmsBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#dmsBut').removeClass("viewing") } if (winNow == posRoiNow * 3) { $('#techBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#techBut').addClass("viewing") } else { $('#techBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#techBut').removeClass("viewing") } if (winNow == posRoiNow * 4) { $('#impBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#impBut').addClass("viewing") } else { $('#impBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#impBut').removeClass("viewing") } if (winNow == posRoiNow * 5) { $('#virBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#virBut').addClass("viewing") } else { $('#virBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#virBut').removeClass("viewing") } if (winNow == posRoiNow * 6) { $('#biBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#biBut').addClass("viewing") } else { $('#biBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#biBut').removeClass("viewing") } if (winNow == posRoiNow * 7) { $('#contBut a img.active').stop().animate({ opacity: 1 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#contBut').addClass("viewing") } else { $('#contBut a img.active').stop().animate({ opacity: 0 }, { queue: false, duration: 300, easing: "easeOutExpo" }); $('#contBut').removeClass("viewing") } };

    Read the article

  • Can't focus fancybox iframe input

    - by bswinnerton
    So I'm using fancybox to load up a login iframe, and I would like it onComplete to bring focus to the username field. If someone could take a look at this code and let me know what's wrong, that'd be great. Gracias. /* Function to resize the height of the fancybox window */ (function($){ $.fn.resize = function(width, height) { if (!width || (width == "inherit")) inner_width = parent.$("#fancybox-inner").width(); if (!height || (height == "inherit")) inner_height = parent.$("#fancybox-inner").height(); inner_width = width; outer_width = (inner_width + 14); inner_height = height; outer_height = (inner_height + 14); parent.$("#fancybox-inner").css({'width':inner_width, 'height':inner_height}); parent.$("#fancybox-outer").css({'width':outer_width, 'height':outer_height}); } })(jQuery); $(document).ready(function(){ var pasturl = parent.location.href; $("a.iframe#register").fancybox({ 'transitionIn' : 'fade', 'transitionOut' : 'fade', 'speedIn' : 600, 'speedOut' : 350, 'width' : 450, 'height' : 385, 'scrolling' : 'no', 'autoScale' : false, 'autoDimensions' : false, 'overlayShow' : true, 'overlayOpacity' : 0.7, 'padding' : 7, 'hideOnContentClick': false, 'titleShow' : false, 'onStart' : function() { $.fn.resize(450,385); }, 'onComplete' : function() { $("#realname").focus(); }, 'onClosed' : function() { $(".warningmsg").hide(); $(".errormsg").hide(); $(".successfulmsg").hide(); } }); $("a.iframe#login").fancybox({ 'transitionIn' : 'fade', 'transitionOut' : 'fade', 'speedIn' : 600, 'speedOut' : 350, 'width' : 400, 'height' : 250, 'scrolling' : 'no', 'autoScale' : false, 'overlayShow' : true, 'overlayOpacity' : 0.7, 'padding' : 7, 'hideOnContentClick': false, 'titleShow' : false, 'onStart' : function() { $.fn.resize(400,250); }, 'onComplete' : function() { $("#login_username").focus(); }, 'onClosed' : function() { $(".warningmsg").hide(); $(".errormsg").hide(); $(".successfulmsg").hide(); } }); $("#register").click(function() { $("#login_form").hide(); $(".registertext").hide(); $.fn.resize(450,385); $("label").addClass("#register_form label"); }); $("#login").click(function() { $.fn.resize(400,250); $("label").addClass("#login_form label"); }); $("#register_form").bind("submit", function() { $(".warningmsg").hide(); $(".errormsg").hide(); $(".successfulmsg").hide(); if ($("#realname").val().length < 1 || $("#password").val().length < 1 || $("#username").val().length < 1) { $("#no_fields").addClass("warningmsg").show().resize(inherit,405); return false; } if ($("#password").val() != $("#password2").val()) { $("#no_pass_match").addClass("errormsg").show().resize(); return false; } $.fancybox.showActivity(); $.post( "../../admin/users/create_submit.php", { realname:$('#realname').val(), email:$('#email').val(), username:$('#username').val(), password:MD5($('#password').val()), rand:Math.random() } ,function(data){ if(data == "OK"){ $(".registerbox").hide(); $.fancybox.hideActivity(); $.fn.resize(inherit,300); $("#successful_login").addClass("successfulmsg").show(); } else if(data == "user_taken"){ $.fancybox.hideActivity(); $("#user_taken").addClass("errormsg").show().resize(inherit,405); $("#username").val(""); } else { $.fancybox.hideActivity(); document.write("Well, that was weird. Give me a shout at [email protected]."); } return false; }); return false; }); $("#login_form").bind("submit", function() { $(".warningmsg").hide(); $(".errormsg").hide(); $(".successfulmsg").hide(); if ($("#login_username").val().length < 1 || $("#login_password").val().length < 1) { $("#no_fields").addClass("warningmsg").show().resize(inherit,280); return false; } $.fancybox.showActivity(); $.post( "../../admin/users/login_submit.php", { username:$('#login_username').val(), password:MD5($('#login_password').val()), rand:Math.random() } ,function(data){ if(data == "authenticated"){ $(".loginbox").hide(); $(".registertext").hide(); $.fancybox.hideActivity(); $("#successful_login").addClass("successfulmsg").show(); parent.document.location.href=pasturl; } else if(data == "no_user"){ $.fancybox.hideActivity(); $("#no_user").addClass("errormsg").show().resize(); $("#login_username").val(""); $("#login_password").val(""); } else if(data == "wrong_password"){ $.fancybox.hideActivity(); $("#wrong_password").addClass("warningmsg").show().resize(); $("#login_password").val(""); } else { $.fancybox.hideActivity(); document.write("Well, that was weird."); } return false; }); return false; }); }); And here is the HTML: <p><a class="iframe" id="login" href="/login/">Login</a></p>

    Read the article

  • Big task - problems with page refresh and ajax

    - by user1830414
    I have a navigation which load dynamically content via ajax. But if I refresh the page or visit another url and go back the current content is away and I see the old content under the first menu tab. Now I have to solve this problem. The index.php include the elements header_registrated.inc.php, navigation.inc.php and main_container.inc.php index.php: <?php include("inc/incfiles/header_registrated.inc.php"); ?> <?php if (!isset($_SESSION["userLogin"])) { echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/project\">"; } else { echo ""; } ?> <?php include("inc/incfiles/navigation.inc.php"); ?> <?php include("inc/incfiles/main_container.inc.php"); ?> <?php include("inc/incfiles/footer.inc.php"); ?> header_registrated.inc.php: <?php include ("inc/scripts/mysql_connect.inc.php"); session_start(); $user = $_SESSION["userLogin"]; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>title</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" src="js/framework/jquery.js"></script> <script language="JavaScript" src="js/dropdown/window.js"></script> <script language="JavaScript" src="js/navigation/navigation.js"></script> </head> <body> </body> navigation.inc.php: <div class="navigation"> <ul> <li id="1"> <div id="menuImage1" class="menuImage"></div> <div class="menuText"><p>Punkt 1</p></div> <div class="navigationDart"></div> </li> <li id="2"> <div id="menuImage2" class="menuImage"></div> <div class="menuText"><p>Punkt 2</p></div> </li> <li id="3"> <div id="menuImage3" class="menuImage"></div> <div class="menuText"><p>Punkt 3</p></div> </li> <li id="4"> <div id="menuImage4" class="menuImage"></div> <div class="menuText"><p>Punkt 4</p></div> </li> <li id="5"> <div id="menuImage5" class="menuImage"></div> <div class="menuText"><p>Punkt 5</p></div> </li> <li id="6"> <div id="menuImage6" class="menuImage"></div> <div class="menuText"><p>Punkt 6</p></div> </li> </ul> </div> main_container.inc.php: <div class="mainContainer"> <div class="containerHeader"> <div class="contentHeader"> </div> </div> <div class="contentContainer"> <div class="content"> </div> <div class="advertisement"> </div> </div> </div> Now the divs content, cnotentHeader and advertisement (in file main_content.inc.php) is filled via ajax. Also the navigation has some jquery effects which also have to be the same after page refresh. navigation.js: $(document).ready(function() { $.get('inc/incfiles/content_container/header/1.php', function(data) { $('.contentHeader').html(data); }); $.get('inc/incfiles/content_container/content/1.php', function(data) { $('.content').html(data); }); $.get('inc/incfiles/content_container/advertisement/1.php', function(data) { $('.advertisement').html(data); }); var current = '1.php'; $(".navigation li").click(function() { var quelle = $(this).attr('id') + ".php"; // the current content doesn't load again if(current === quelle) { return; } current = quelle; // content $(".content").fadeOut(function() { $(this).load("inc/incfiles/content_container/content/" + quelle).fadeIn('normal'); }) // advertisement $(".advertisement").fadeOut(function() { $(this).load("inc/incfiles/content_container/advertisement/" + quelle).fadeIn('normal'); }) // header $(".contentHeader").fadeOut(function() { $(this).load("inc/incfiles/content_container/header/" + quelle).fadeIn('normal'); }) }); $(".navigation li").click(function() { $(".menuImage").removeClass("menuImageActive1"); $(".menuImage").removeClass("menuImageActive2"); $(".menuImage").removeClass("menuImageActive3"); $(".menuImage").removeClass("menuImageActive4"); $(".menuImage").removeClass("menuImageActive5"); $(".menuImage").removeClass("menuImageActive6"); }); $("#1").mousedown(function() { $("#menuImage1").addClass("menuImageClick1"); // new class on mouse button press }); $("#1").mouseup(function() { $("#menuImage1").removeClass("menuImageClick1"); //remove class after mouse button release }); $("#1").click(function() { $("#menuImage1").addClass("menuImageActive1"); }); $("#2").mousedown(function() { $("#menuImage2").addClass("menuImageClick2"); // new class on mouse button press }); $("#2").mouseup(function() { $("#menuImage2").removeClass("menuImageClick2"); //remove class after mouse button release }); $("#2").click(function() { $("#menuImage2").addClass("menuImageActive2"); }); $("#3").mousedown(function() { $("#menuImage3").addClass("menuImageClick3"); // new class on mouse button press }); $("#3").mouseup(function() { $("#menuImage3").removeClass("menuImageClick3"); //remove class after mouse button release }); $("#3").click(function() { $("#menuImage3").addClass("menuImageActive3"); }); $("#4").mousedown(function() { $("#menuImage4").addClass("menuImageClick4"); // new class on mouse button press }); $("#4").mouseup(function() { $("#menuImage4").removeClass("menuImageClick4"); //remove class after mouse button release }); $("#4").click(function() { $("#menuImage4").addClass("menuImageActive4"); }); $("#5").mousedown(function() { $("#menuImage5").addClass("menuImageClick5"); // new class on mouse button press }); $("#5").mouseup(function() { $("#menuImage5").removeClass("menuImageClick5"); //remove class after mouse button release }); $("#5").click(function() { $("#menuImage5").addClass("menuImageActive5"); }); $("#6").mousedown(function() { $("#menuImage6").addClass("menuImageClick6"); // new class on mouse button press }); $("#6").mouseup(function() { $("#menuImage6").removeClass("menuImageClick6"); //remove class after mouse button release }); $("#6").click(function() { $("#menuImage6").addClass("menuImageActive6"); }); $("#1").click(function(){ $(".navigationDart").animate({ top: "16px" }, 500 ); }); $("#2").click(function(){ $(".navigationDart").animate({ top: "88px" }, 500 ); }); $("#3").click(function(){ $(".navigationDart").animate({ top: "160px" }, 500 ); }); $("#4").click(function(){ $(".navigationDart").animate({ top: "232px" }, 500 ); }); $("#5").click(function(){ $(".navigationDart").animate({ top: "304px" }, 500 ); }); $("#6").click(function(){ $(".navigationDart").animate({ top: "376px" }, 500 ); }); }); My idea was it to work with if(isset($_SESSION['ajaxresponse'])) but I don't no how to do this. Please help me. I have the feeling that I've searched the whole web to find an answer.

    Read the article

  • jQuery date calculator - show/hide IMG

    - by utopicam
    I have a problem with the following code. I tried changing many things (symbols, classes, imgs in the code) but this is killing me and I have no idea how to fix it. Sorry it's so specific, when solved I'll change the title to something more useful. I have two images. My jquery has to calculate the day and show one image or the other depending on that (using a class with display:none). My month has 24 days (it's a xmas thing). This is what I have so far: <script type="text/javascript"> $(document).ready(function(){ var currentTime = new Date() var day = currentTime.getDate(); if (day > 24){ day = 1; } $(".calDate").each(function(){ var curDate = $(this).attr("date"); if (curDate < day){ $(this).addClass("xMasPast"); } else if(curDate==day){ $(this).addClass("xMasActive"); } else { $(this).addClass("xMasInactive"); } }); $(".calDate2").each(function(){ var curDate = $(this).attr("date"); if (curDate > day){ $(this).addClass("xMasInactive"); } else if(curDate==day){ $(this).addClass("xMasActive"); } else { $(this).addClass("xMasActive"); } }); }); </script> But it's showing all the images. What am I missing? (any ideas on making the code simpler are more than welcomed). Thanks for your help! Update: simplified HTML <div><img src="day21.png" which="21"/></a></div> <img id="bola21" class="calDate2" src="day21.png"/>

    Read the article

  • jQuery getting these functions to work together

    - by brett
    I'm new to jQuery and have tried looking around for an answer on how to do this. I have 2 functions and I would like both to work together. The one function is submitHandler and its used to hide a form and at the same time add a class to a hidden element to unhide it - ie a thank you for submitting h1. The other function is to grab the input data and display it onsubmit in the form. So the problem is that I can get that one to work but then the other doesnt. Ie on form submit I can see the data input but not the h1 Thank you message. Here are the functions: SubmitHandler: submitHandler: function() { $("#content").empty(); $("#content").append( "<p>If you want to be kept in the loop...</p>" + "<p>Or you can contact...</p>" ); $('h1.success_').removeClass('success_').addClass('success_form'); $('#contactform').hide(); }, onsubmit="return inputdata()" function inputdata(){ var usr = document.getElementById('contactname').value; var eml = document.getElementById('email').value; var msg = document.getElementById('message').value; document.getElementById('out').innerHTML = usr + " " + eml + msg; document.getElementById('out').style.display = "block"; return true; }, The form uses PHP and jQuery - I dont know about AJAX but after some reading even less sure. Please help me out I dont know what I'm doing and at the moment I am learning but its a long road for me still. Thank you The form: <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform" onsubmit="return inputdata()"> <div class="_required"><p class="label_left">Name*</p><input type="text" size="50" name="contactname" id="contactname" value="" class="required" /></div><br/><br/> <div class="_required"><p class="label_left">E-mail address*</p><input type="text" size="50" name="email" id="email" value="" class="required email" /></div><br/><br/> <p class="label_left">Message</p><textarea rows="5" cols="50" name="message" id="message" class="required"></textarea><br/> <input type="submit" value="submit" name="submit" id="submit" /> </form> The PHP bit: <?php $subject = "Website Contact Form Enquiry"; //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = '[email protected]'; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ? The Jquery Validate bit: $(document).ready(function(){ $('#contactform').validate({ showErrors: function(errorMap, errorList) { //restore the normal look $('#contactform div.xrequired').removeClass('xrequired').addClass('_required'); //stop if everything is ok if (errorList.length == 0) return; //Iterate over the errors for(var i = 0;i < errorList.length; i++) $(errorList[i].element).parent().removeClass('_required').addClass('xrequired'); }, Here is the full jQuery bit: $(document).ready(function(){ $('#contactform').validate({ showErrors: function(errorMap, errorList) { //restore the normal look $('#contactform div.xrequired').removeClass('xrequired').addClass('_required'); //stop if everything is ok if (errorList.length == 0) return; //Iterate over the errors for(var i = 0;i < errorList.length; i++) $(errorList[i].element).parent().removeClass('_required').addClass('xrequired'); }, submitHandler: function() { $('h1.success_').removeClass('success_').addClass('success_form'); $("#content").empty(); $("#content").append('#sadhu'); $('#contactform').hide(); }, }); }); Latest edit - Looks like this: $(document).ready(function(){ $('#contactform').validate({ showErrors: function(errorMap, errorList) { //restore the normal look $('#contactform div.xrequired').removeClass('xrequired').addClass('_required'); //stop if everything is ok if (errorList.length == 0) return; //Iterate over the errors for(var i = 0;i < errorList.length; i++) $(errorList[i].element).parent().removeClass('_required').addClass('xrequired'); }, function submitHandler() { $('h1.success_').removeClass('success_').addClass('success_form'); $("#content").empty(); $("#content").append('#sadhu'); $('#contactform').hide(); }, function inputdata() { var usr = document.getElementById('contactname').value; var eml = document.getElementById('email').value; var msg = document.getElementById('message').value; document.getElementById('out').innerHTML = usr + " " + eml + msg; document.getElementById('out').style.display = "block"; }, $(document).ready(function(){ $('#contactForm').submit(function() { inputdata(); submitHandler(); }); }); });

    Read the article

  • jquery Ajax $.ajaxError

    - by cf_PhillipSenn
    I have a bunch of ajax calls that contain success and error conditions like this one: $.ajax({ url: 'Remote/State.cfc' ,type: "POST" ,data: { 'method': 'UpdateStateName' ,'StateID': StateID ,'StateName': StateName } ,success: function(result){ if (isNaN(result)) { $('#msg').text(result).addClass('err'); } else { $('#' + result + ' input[name="StateName"]').addClass('changed'); }; } ,error: function(msg){ $('#msg').text('Connection error').addClass('err'); } }); All the error conditions are the same. In other words, they all put the phrase "Connection error" in the msg id. Q1: Could I remove all these and replace them with $().ajaxError(function(myEvent, request, settings, thrownError) { $('#msg').text('Connection error').addClass('err'); }); Q2: How would you use myEvent and request to display a more informative error message?

    Read the article

  • Create Clone Without Effecting Results of Original Object

    - by user1655096
    I have a function that when selecting an option, returns results. I want to be able to clone that function and have the ability to return another set of results, without adding the new results to the original object. // shows / hides results based on selection $(".categories-select").live("change" ,function(){ if($(this).val() == 'red'){ $('.red').removeClass('hide'); // toggles red results, sub menus $(this).parent('.controls').find('.sub').removeClass('hide'); } if($(this).val() == 'blue'){ $('.blue').removeClass('hide'); $(this).parent('.controls').find('.sub').addClass('hide'); } if($(this).val() == 'purple'){ $('.purple').removeClass('hide'); $(this).parent('.controls').find('.sub').addClass('hide'); } if($(this).val() == 'orange'){ $('.orange').removeClass('hide'); $(this).parent('.controls').find('.sub').addClass('hide'); } }); // Duplicates category select menu $(".add-color").find(function(){ $(".color-category").clone().removeClass('color-category').appendTo("#we-want-to").find('.sub,').addClass('hide') ; }); $(".add-color-alternate").click(function(){ $(".color-category-alternate").clone().removeClass('color-category-alternate').appendTo("#we-want-to").find('.sub, .results-table').addClass('hide'); });

    Read the article

  • How to wait for ajax validation to complete before submitting a form?

    - by Jung
    Having a problem where the form submits before the validateUsername function has a chance to complete the username check on the server-side. How do I submit the form only after the validateUsername function completes? Hope this is clear... form.submit(function(){ if (validateUsername() & validateEmail() & validatePassword()) { return true; } else { return false; } }); function validateUsername(){ usernameInfo.addClass("sign_up_drill"); usernameInfo.text("checking..."); var b = username.val(); var filter = /^[a-zA-Z0-9_]+$/; $.post("../username_check.php",{su_username:username.val()},function(data) { if (data=='yes') { username.addClass("error"); usernameInfo.text("sorry, that one's taken"); usernameInfo.addClass("error"); return false; } else if (!filter.test(b)) { username.addClass("error"); usernameInfo.text("no funny characters please"); usernameInfo.addClass("error"); return false; } else { username.removeClass("error"); usernameInfo.text("ok"); usernameInfo.removeClass("error"); return true; } }); }

    Read the article

  • Toggling between states on 3 containers in jQuery

    - by Saif Bechan
    Hello, i have an php/mysql/ajax auction application application. Now there is a section that can have 3 states. State one, the user can place a bid.(Bid button is shown) State two, the user has to wait before he can place a new bid(number of sec is shown) State three, the user has an auto bidding system enabled.(The price maximum and amount ate shown). Now i get these values trough jquery ajax, and i want to present the user the right section. Now the code i have is as follows: if(data[i].bidwait >= 0 && data[i].amount == ''){ // In this section the user has no autobiddings, and can place a bidding $(productContainer+' .bid-wrapper').removeClass('none'); $(productContainer+' .bidwait-wrapper').addClass('none'); $(productContainer+' .autobid-wrapper').addClass('none'); }else if(data[i].bidwait < 0 && data[i].amount == ''){ // In this section the user has to wait the amount of sec to place a new bid $(productContainer+' .bid-wrapper').addClass('none'); $(productContainer+' .bidwait-wrapper').removeClass('none'); $(productContainer+' .autobid-wrapper').addClass('none'); $(productContainer+' .bidwait-text').text(data[i].bidwait * -1); }else{ // In the last section the user has the auto bidder enabled, so that is shown $(productContainer+' .bid-wrapper').addClass('none'); $(productContainer+' .bidwait-wrapper').addClass('none'); $(productContainer+' .autobid-wrapper').removeClass('none'); $(productContainer+' .amount').html(data[i].amount == 0 ? '&#8734;' : data[i].amount); $(productContainer+' .maxprice').html(data[i].maxprice == 0 ? '&#8734;' : data[i].maxprice); } This looks like an awful lot of code for something so small. I was wondering if there is an easier method to accomplish such a thing. Speed is a huge issue for me because this has to run every second in the users browser. If there is no other option i am just going to remove this option and go with a no ajax approuch. If you have been, thank you for reading!

    Read the article

  • XMLHttpRequest not working, trying to test database connection [closed]

    - by Frederick Marcoux
    I'm currently creating my own CMS for personnal use but I'm blocked at a code. I'm trying to make a installation script but the AJAX request to test if database works, doesn't work... There's my JS code: function testDB() { "use strict"; var host = document.getElementById('host').value; var username = document.getElementById('username').value; var password = document.getElementById('password').value; var db = document.getElementById('db_name').value; var xmlhttp = new XMLHttpRequest(); var url = "test_db.php"; var params = "host="+host+"&username="+username+"&password="+password+"&db="+db; xmlhttp.open("POST", url, true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); $('#loader').removeAttr('style'); if (xmlhttp.responseText !== '') { if (xmlhttp.readyState===4 && xmlhttp.status===200) { $('#next').removeAttr('disabled'); $('#test').attr('disabled', 'disabled'); $('#test').text('Connection Successful!'); $('#test').addClass('btn-success'); $('#login').addClass('success'); $('#login1').addClass('success'); $('#db').addClass('success'); $('#loader').attr('style', 'display: none;'); } else { $('#next').attr('disabled', 'disabled'); $('#test').removeClass('btn-success'); $('#test').removeAttr('disabled'); $('#test').text('Test Connection'); $('#login').removeClass('success'); $('#login1').removeClass('success'); $('#db').removeClass('success'); $('#loader').attr('style', 'display: none;'); } } else { $('#next').attr('disabled', 'disabled'); $('#next').attr('disabled', 'disabled'); $('#test').removeClass('btn-success'); $('#test').removeAttr('disabled'); $('#test').text('Test Connection'); $('#login').removeClass('success'); $('#login1').removeClass('success'); $('#db').removeClass('success'); $('#loader').attr('style', 'display: none;'); } } And there's my PHP code: <?php $link = mysql_connect($_POST['host'], $_POST['username'], $_POST['password']); if (!$link) { echo ''; } else { if (mysql_select_db($_POST['db'])) { echo 'Connection Successful!'; } else { echo ''; } } mysql_close($link); ?> I don't know why it doesn't work but I tried with JQuery $.ajax, $.get, $.post but nothing work...

    Read the article

  • Replace Javascript click event with timed event?

    - by Rik
    Hi, I've found some javascript code that layers photos on top of each other when you click on them. Rather than having to click I'd like the function to automatically run every 5 seconds. How can I change this event to a timed one: $('a#nextImage, #image img').click(function(event){ Full code below. Thanks <script type="text/javascript"> $(document).ready(function(){ $('#description').css({'display':'block'}); $('#image img').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); }); $('a#nextImage, #image img').click(function(event){ event.preventDefault(); $('#description p:first-child').css({'visibility':'hidden'}); if($('#image img.current').next().length){ $('#image img.current').removeClass('current').next().fadeIn('normal').addClass('current').css({'position':'absolute'}); }else{ $('#image img').removeClass('current').css({'display':'none'}); $('#image img:first-child').fadeIn('normal').addClass('current').css({'position':'absolute'}); } if($('#image img.current').width()>=($('#page').width()-100)){ xPos=170; }else{ do{ xPos = 120 + (Math.floor(Math.random()*($('#page').width()-100))); }while(xPos+$('#image img.current').width()>$('#page').width()); } if($('#image img.current').height()>=300){ yPos=0; }else{ do{ yPos = Math.floor(Math.random()*300); }while(yPos+$('#image img.current').height()>300); } $('#image img.current').css({'left':xPos,'top':yPos}); }); });

    Read the article

  • Shortening jQuery Code by Replacing Variable

    - by Jerry
    I have a form with a bunch of dropdown options that I'm dressing up by allowing the option to be selected by clicking links and (in the future, images) instead of using the actual dropdown. There are a lot of dropdowns and most all will repeat the same basic idea, and some will literally repeat just with different variables. Here's the HTML for one of those. <tr class="box1"> <td> <select id="cimy_uef_7"> <option value="Boy">Boy</option> <option value="Girl">Girl</option> </select> </td> </tr> Then the corresponding fancier links to click that will select the corresponding option in the dropdown. <div id="genderBox1"> <div class="gender"><a class="boy" href="">Boy</a></div> <div class="gender"><a class="girl" href="">Girl</a></div> </div> So, when you click the link "Boy" it will select the corresponding dropdown value "Boy" There are going to be multiple Box#, so I can just repeat the jQuery each time with the new variables, but there's surely a shorter way. Here's the jQuery that makes it work. //Box1 Gender var Gender1 = $('select#cimy_uef_7'); var Boy1 = $("#genderBox1 .gender a.boy"); var Girl1 = $("#genderBox1 .gender a.girl"); //On Page Load - Check Gender Box 1 Selection and addClass to corresponding div a if ( $(Gender1).val() == "Boy" ) { $(Boy1).addClass("selected"); } else { $(Boy1).removeClass("selected"); } if ( $(Gender1).val() == "Girl" ) { $(Girl1).addClass("selected"); } else { $(Girl1).removeClass("selected"); } //On Click - Change Gender Box 1 select based on image click $(Boy1).click(function(event) { event.preventDefault(); $(this).addClass("selected"); $(Gender1).val("Boy"); $(Girl1).removeClass("selected"); }); $(Girl1).click(function(event) { event.preventDefault(); $(this).addClass("selected"); $(Gender1).val("Girl"); $(Boy1).removeClass("selected"); }); My thought for shortening it was to just have a list of variables for each box and cycle through the numbers- 1,2,3,4 and have the jQuery grab the same # for each variable, but I can't figure out a way to do it. Let me know if there's anything else I can provide to make the question better. This is my best idea for shortening this code, as I'm still very much a beginner at jQuery, but I'm positive there are much better ideas out there, so feel free to recommend a better path if you see it :)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >