JavaScript - Skipping If Else?
Hii guys..
Im pretty new to Javascript and cant get this working.. Code: <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> </head> <body> <script type="text/javascript"> function checkIt(evt) { evt = (evt) ? evt : window.event var charCode = (evt.which) ? evt.which : evt.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) { status = "This field accepts numbers only." return false } status = "" return true } function notEmpty(){ var n = document.getElementById('myText').value if (n<100) test1(); else if(n<200) test2(); else {alert("You did not enter a number!")} } return:false $(function test1() { {alert("1")} }); $(function test2() { {alert("2")} }); </script> <INPUT TYPE="text" NAME="numeric" onKeyPress="return checkIt(event)" id="myText"> <input type='button' onclick='notEmpty()' value='Form Checker' /> </body> Hes running function test1 and function test2 straight without looking at the if else statment, what im doing wrong? Anyway thanks for helping me Greetz Lennard Similar TutorialsI've got an old school script running a static slide show, but it's not showing the ninth image - regardless of what the image is (ruling out a typo in my image file). Here's the page and script: http://www.agwprefinished.com/handpainted.asp Code: <SCRIPT LANGUAGE="JavaScript"> <!-- /* Script by FPMC at http://jsarchive.8m.com Submitted to JavaScript Kit (http://javascriptkit.com) For this and 400+ free scripts, visit http://javascriptkit.com */ //set image paths src = [ "images/faux-stone.jpg", "images/dining-inlay.jpg", "images/dining-inlay-detail.jpg", "images/faux-inlaid-marble-limestone.jpg", "images/faux-marble-inlay-manhattan.jpg", "images/foyer-inlay.jpg", "images/foyer-inlay-detail.jpg", "images/weathered-grain-1.jpg", "images/weathered-grain-detail.jpg", "images/weathered-grain-2.jpg", "images/weathered-grain-3.jpg", "images/ebonized-oak.jpg", "images/aged-oak.jpg", "images/ebonized-oak-transition.jpg", "images/sample.jpg", "images/faux-marble-tile.jpg", "images/faux-marble-tile-2.jpg", "images/faux-marble-medallion.jpg", "images/metallic-1.jpg", "images/metallic-2.jpg", "images/painted-pattern-bath.jpg", "images/painted-pattern-detail.jpg", "images/faux-parkay-4.jpg", "images/faux-parkay-3.jpg", "images/faux-parkay-2.jpg", "images/border-stencil-1.jpg", "images/border-stencil-2.jpg", "images/monogram.jpg", "images/dining-stencil.jpg", "images/reproduction-border.jpg", "images/reproduction-border-detail.jpg", "images/reproduction-hall.jpg", "images/inlay-pattern-hall.jpg", "images/modello-samples-1.jpg", "images/modello-samples-2.jpg", "images/pavlosk-inlay-imitation.jpg", "images/st-peter-inlay.jpg", ] //set corresponding urls url = [""] //set duration for each image duration = 4; //Please do not edit below ads=[]; ct=0; function switchAd() { var n=(ct+1)%src.length; if (ads[n] && (ads[n].complete || ads[n].complete==null)) { document["Ad_Image"].src = ads[ct=n].src; } ads[n=(ct+1)%src.length] = new Image; ads[n].src = src[n]; setTimeout("switchAd()",duration*1000); } function doLink(){ location.href = url[ct]; } onload = function(){ if (document.images) switchAd(); } //--> </SCRIPT> i know there are pre-made scripts to do what i'm doing. i want to create this myself to learn. i'm trying to create a list of section titles with arrows next to them, clicking on an arrow expands the section to read it's text, clicking on the arrow again collapses the section text. additionally, i would like an "expand all" and "collapse all" link and that's where my issue baffles me. my js - Code: function expandAll() { var collapsedDivs = document.getElementsByClassName('collapsed'); for (var i=0; i<collapsedDivs.length; i++) { var expandMe = collapsedDivs[i]; expandMe.style.display = 'block'; expandMe.addClassName('expanded'); expandMe.removeClassName('collapsed'); document.getElementById('arrow_'+i).innerHTML = '<img src="../media/hide.gif" />'; } } my html - Code: <div style="float:left" id="arrow_0"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION ONE TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section one text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_1"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION TWO TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section two text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_2"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION THREE TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section three text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_3"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION FOUR TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section four text text text text text text text text text text text text text text text text text text text text text text </div> upon executing the function, the result is the text for sections one and three being expanded and the arrows for one and two being changed. why? what am i doing wrong? |