JavaScript - Nested If Syntax Error
Hopefully this is something easy to fix. I am using Javascript in Adobe Pro 9 for a form and though I managed to get a different if/else to work, this nested one is giving me fits. If anyone could correct, I would like to know why it fails. I get the following error which highlights the blue line of code:
SyntaxError: syntax error 169: at line 170 Code: var ACDex = this.getField("ACDex"); var ArmorMaxDex = this.getField("ArmorMaxDex").value; var ShieldMaxDex = this.getfield("ShieldMaxDex").value; if(ArmorMaxDex => ShieldMaxDex){ if(ArmorMaxDex => DexMod){ ACDex.value = ArmorMaxDex; }Else{ ACDex.value = DexMod; } }Else{ if(ShieldMaxDex => DexMod) { ACDex.value = ShieldMaxDex; }Else{ ACDex.value = DexMod; } } Similar Tutorials(just started JS 2 weeks ago) -- this is also my first time posting here, if my post isnt following the proper template let me know and Ill fix it .. Thanks so much for taking the time to check this out in advance Im trying to make the first ul tag in the each slideMenus[] array index values have a position of left = 0px I keep recieving this error however ____________________________________________________ Error: slideMenus[i].getElementsByTagName("ul").style is undefined Line: 63 ------------------------------------------------------------------ the script in question is in [code]. Could someone tell me if I am just making a syntax error if not ill try redoing the whole thing. window.onload = makeMenus var currentSlide = null var timeID = null leftPos = 0 function makeMenus(){ var slideMenus = new Array() var allElems = document.getElementsByTagName("*") var slideListArr = new Array() for(var i=0 ; i < allElems.length ; i++){ if(allElems[i].className = "slideMenu") slideMenus.push(allElems[i]) } for(var i=0 ; i < slideMenus.length ; i++){ slideMenus[i].onclick = showSlide; Code: slideMenus[i].getElementsByTagName("ul")[0].style.left = "0px"; } document.getElementById("head").onClick = closeSlide document.getElementById("main").onClick = closeSlide } function showSlide(){ var slideList = this.getElementsByTagName("ul")[0] // mess with this if((currentSlide != null) && (currentSlide.id == slideList.id)) {closeSlide()} else{ closeSlide(); var currentSlide = slideList; currentSlide.style.display = "block"; timeID = setInterval('moveSlide()', 1); } } function closeSlide(){ if(currentSlide){ clearInterval(timeID); currentSlide.style.left = "0px" currentSlide.style.display = "none"; var currentSlide = null } } function moveSlide(){ var leftPos = leftPos + 5; if(leftPos <= 220) {currentSlide.style.left = leftPos + "px"} else{ clearInterval(timeID); var leftPos = 0} } Code: out += (out ? rogueArray[14] : rogueArray[13]) + arrayItem + ((vanWilder[arrayItem] !== null) ? = + encodeURIComponent(vanWilder[arrayItem]) : rogueArray[13]); There is supposedly a syntax error here on the line up until [arrayItem in Dreamweaver. Any help? On this page http://jimpix.co.uk/ecards/262-no-words.html I get this Javascript error in IE6: Code: Line: 5 Character: 1 Code: 0 Error Message: Syntax error URL: http://jimpix.co.uk/ecards/262-no-words.html I'm using the DebugBar add in for IE (http://www.debugbar.com/) The error message in DebugBar is this: http://jimpix.co.uk/junk/error.png And the view-source of the page is he http://jimpix.co.uk/junk/source-code.png I don't get the error in Firefox 3 or IE7. I can't work out how to fix it. Any advice would be much appreciated. Thanks! Can someone point where i'm going wrong? I want to evaluate the values of 'miles' to be >=0 and 'putime' to between 0 and 24 only. Code: <script type = "text/javascript"> function TaxiFare() { // calculates taxi fare based upon miles travelled // and the hour of the day in military time (0-23). var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var milesTravelled = Number(document.getElementById("miles").value); var pickupTime = Number(document.getElementById("putime").value); var cost = baseFare + (costPerMile * milesTravelled); // add the nightSurcharge to the cost if it is after // 10pm or before 6am if (pickupTime >= 22 || pickupTime < 6) { cost += nightSurcharge; } if((document.getElementById('miles').value>=0)&&(document.getElementById('putime').value>=0||<=24) { alert("Your taxi fare is $" + cost.toFixed(2)); } else{return 0;} } </script> why does my javascript function run right away when the page loads? but not wen the button is clicked? its working the opposite to how i want it to i didnt include the other html tags to help focus on this. Btw im tryna avoid the method of having the onclick="funct()" method which would be written in the button tag. Thank you. <body> <button id="mybutton">Click me</button> </body> <script type = "text/javascript"> var b = document.getElementById("mybutton"); b.onclick = funct() function funct() { alert("Thanks for clicking me!"); } </script> Hi, Im currently building my first website, I'm trying to use a JQuery Slider effect for a top banner, however I seem to be getting a syntax error after the javascript. Any ideas? Ive attached a screenshot of the code Thanks Simon Dreamweaver is giving me a syntax error, but i dont understand what is wrong. i copied the line from the source code of the demo file included in the download and it it still telling me there is a syntax error. obviously something is wrong bc my slider isnt auto-sliding. so then i tried copying and pasting from the source code of the web page i got the slider from (http://www.ndoherty.biz/demos/coda-slider/2.0/) Dreamweaver then moved the syntax error warning to the line that only contains my closing script tag what am i doing wrong? why am i getting syntax errors? how can i make this thing autoslide? full code available at: http://mydomainsample.com/fire_rebuild greetings, I'm unable to find solution for dreamweaver reporting syntax error with the following page: http://www.redskyjewelry.com/test_product_detail.html I am revamping my website so the css is not set up for this page but that's okay. I have put in the various javascripts based on the product so the page is similar to a template. The syntax error is for the second set of boxes, the bracelet length options, and specifically for line with: form.amount.value = 6.5 inches; from the following script-- <SCRIPT language=javascript> function BraceletLength(form) { if (form.os0.value == "6.5 inches") { form.amount.value = 6.5 inches; form.item_number.value = "6.5 inches"; } if (form.os0.value == "7 inches") { form.amount.value = 7 inches; form.item_number.value = "7 inches"; } if (form.os0.value == "7.5 inches") { form.amount.value = 7.5 inches; form.item_number.value = "7.5 inches"; } if (form.os0.value == "8 inches") { form.amount.value = 8 inches; form.item_number.value = "8 inches"; } } </SCRIPT> I hope I have included enough information and I thank any input into this glitch I am having. I'll check back tomorrow, and thank you. judith I'm trying to render 14 same sized images on a webpage using a Javascript, I've used in the past, but now can't seem to get it to work. Getting a Syntax Error. On Page http://www.newenglandonline.net/index.fix.html The ERROR appears to be on the following; line 270: var imageDir = ; [CODE] <script type="text/javascript"> (function() { var rotator = document.getElementById(rotator); var imageDir = ; var delayInSeconds = 3; var images = [Cannon_top.jpg,Mount-Washington-Summer.jpg,Mount-Washington-Winter.jpg,Boston_Charles.jpg,Boston_Harbor.jpg,Boston_Harbor_night.jpg,Zakim Bridge.jpg,Edgartown.jpg,GayHeadLighthouse.jpg,HighlandLight.jpg,Newport.jpg,Bridgeport.jpg,Eastpoin tLight.jpg]; var num = 0; var changeImage = function() { var len = images.length; rotator.src = imageDir + images[num++]; if (num == len) { num = 0; } }; setInterval(changeImage, delayInSeconds * 1000); })(); </script> [CODE] Any help or insight will be greatly appreciated. Thanks in advance. Hi, For the life of me I can't work out what is wrong with the code he http://www.spencercarpenter.co.uk/po...162&fgh=showMe I know it is somthing to do with the url and that it is a synax error but I really am stuck as I cant see what it is. If anyone could help me resolve this I would be very grateful. Thanks for any help. Spencer Hey guys, I've been learning Javascript for a few days using code academy. I've come across this issue, and I'm not sure what exactly I'm doing wrong. Any help would be great. // Check if the user is ready to play! confirm("I am ready to play!"); var age = prompt("What's your age?"); if (age < 13) { console.log("I take no responsiblity, but you are allowed to play") } else { console.log("Have fun!") } console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'") console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'") var userAnswer = prompt("Do you want to race Bieber on stage?"); if userAnswer === "yes" { console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!"); } else { console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'"); } uncaught exception: Syntax error, unrecognized expression:
Code: :([rel*=qnt_Rc]) I have this code: Code: grpDiv = $$('div:([rel*=' + txt_val + '])'); Which when operaterated on, we have: Code: grpDiv = $$('div:([rel*=qnt_Rc]) This error: uncaught exception: Syntax error, unrecognized expression: Code: :([rel*=qnt_Rc]) Is new. The code in question has been around for about a year and no issues with prototype 1.6.1. Yet we upgraded to 1.7, and this error started showing. any ideas what this could be and how to fix it? thanks Hey Guys, I'm currently a seasoned programmer who is in a programming class at my school. We're currently learning advanced JavaScript, and we're on the topic of nested loops. After teaching us about for and while loops, my teacher gave us a little puzzle to solve. It's kind of difficult to explain, but I'll give you guys my current code and what it outputs. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Word Reversal</title> <script type="text/javascript"> var ask = prompt("How many words do you want?",""); while (ask < "1") { alert("You have to have at least one word!"); var ask = prompt("How many words do you want?",""); } var num = parseInt(ask) + 1; var final = ""; for (var i=1; i < num; i++) { var word = prompt("What's word " + i + "?"); final = final + "Word " + i +": " + word + "<br/>"; } </script> </head> <body> <script type="text/javascript"> document.writeln(final); </script> </body> </html> The current output, when the user wants two words, and word 1 is one and word 2 is two, comes out to be: Code: Word 1: one Word 2: two Which is great, but the only problem is, this is what the output's supposed to be: Code: Word 2: two Word 1: one I'm stumped. I've had numerous programming challenges in my life which I've solved, but I'm not sure where to go next on this one. The script is supposed to use a nested loop, but what goes in what loop to reverse the order of the user's input? I asked my teacher for help, but he told me "Ask someone else." I asked another seasoned programmer in my class, who was just about as stumped as I was, so I went back to my teacher. "Well, ask another person" he replied. And can you believe this guy has a Master's Degree of Computer Science? So I'm asking you guys: the community. I hope someone will be able to help me. On top of that, I have to help and tutor two special education students in my class on this kind of stuff during class, and they can't get the project done until I get it done, as they learn from analyzing and copying my work (which my teacher told me to do). They get upset when they have nothing to code, and they end up goofing off the entire period, or using it as a study hall. I need to get them back on track, so we can move on to the next project. Please help me with this code - it would be greatly appreciated. Thank you! Hello. I was wondering if there is a way to call a second Javascript function from within the first. For example: <script>...call first function...</script> Inside first function: If (a==1) <script>...call second function...</script> else (a==2) <script>...call third function...</script> My thinking as to why I would need this is because I need to access two different Google Maps API codes. If that isn't possible, does anyone have any other suggestions? I'm trying to reuse some code in a different context to do a different job. The code to be reused contains hundreds of lines similar to a = new b.c.d(e,f) with different value for e and f. I need to create a new user defined object with the structure b.c.d. I've made numerous attempts along the lines of: Code: function d (e, f) { this.e = e; this.f = f; } function c () { this.d = d (e, f); } function b () { this.c = c; } var a = new b.c.d("test", "message"); with various permuations of functional declarations. However I get error message "Object expected" or "b.c.d is null or not an object" at the final line of the example. It works with the test line var a = new d("test", "message") but not when I start to build up the expression. How should I define of b.c.d? Hello codingforums.com! Right, this is probably going but such a stupid newbie thread but here goes.. I've finally got myself into gear to start learning javascript. I've been watching video tutorials, learning from websites and simply learning by error. I understand the concept of for loops, but the whole nested thing doesn't seem to click for some reason. I thought i understood and managed to write a piece of code that constantly writes '*' across the screen. Could someone with some pretty damn good knowledge of javascript be able to walk me through step by step of my script to explain what actually is happening? It would help loads. here is the script, many thanks!! <script type="text/javascript"> var counter = 0; function writeStars(){ for(i=0;i<1;i++){ for(a=0;a<=counter;a++){ document.write("*"); } counter++ document.write("<br />"); } } setInterval("writeStars()", 200); </script> OK i'm trying to make an affiliate section for my page in javascript, I used double arrays and it's terribly coded. Please help. I'm new to this... Code: <html> <body> <script type="text/javascript"> var alley = new Array(); alley[0] = new Array( "http://stereo.b1.jcink.com/", "http://i49.tinypic.com/5klkb6.gif", "Stereo Wired" ); alley[1] = new Array ( "http://s1.zetaboards.com/N2010/", "http://sixpop.com/files/246/n2010.png", "N2010" ); alley[2] = new Array ( "http://theipodnation.net", "http://img15.imageshack.us/img15/1043/affiipod.png", "The Ipod Nation" ); for ( i = 3; i < alley.length; i++ ) { for ( m = 0; m < alley[i].length; m++ ) { document.write(" <a href='" + alley[i][m][0] + "'><img src='" + alley[i][m][1] + "' alt='" + alley[i][m][2] + "' /></a> ") } } </script> </body> </html> This may be a basic programing problem but I am writing a function to validate a form using a bunch of else-if statements and encounters a problem when I use nested if/else-if statements. It will not continue on to the next else-if, after it returns false. Code: // to check each entry on the form and alert user if entry is invalid. function checkform(){ var checkssn = /(\d{3})-(\d{2})-(\d{4})/; var checkphone = /(\d{3})-(\d{4})/; var checkname = /[a-zA-Z]+(\.|,|\s)*/; var checkzip = /(^967|^968)\d{2}(-\d{4})?$/; // check to see if user have selected an Election if (!document.f1.elections[0].checked && !document.f1.elections[1].checked && !document.f1.elections[2].checked && !document.f1.elections[3].checked) { window.alert("Please select an Election!") return false; // check to see if user entered a valid SSN } else if ( checkssn.test(document.f1.ssn.value) == false){ window.alert("[1]. Please enter a valid social security number in the format ddd-dd-ddd"); return false; // check to see if user entered a valid home telephone number or business telephone number }else if ( document.f1.home_phone.value == '' && document.f1.business_phone.value == '') { window.alert("[4]. Please enter a Home or Business telephone number!") return false; } else if ( document.f1.home_phone.value != ''){ if (checkphone.test(document.f1.home_phone.value) == false){ window.alert("[4]. Please enter a valid home phone number in the format ddd-ddd"); return false; } } else if ( document.f1.business_phone.value != ''){ if ( checkphone.test(document.f1.business_phone.value) == false){ window.alert("[4]. Please enter a valid business phone number in the format ddd-ddd"); return false; } // check to see if user entered a valid Name }else if ( checkname.test(document.f1.lastname.value) == false){ window.alert("[5]. Last Name can only consist of letters, periods(.), commas(,) and spaces"); return false; }else if ( checkname.test(document.f1.firstname.value) == false){ window.alert("[5]. First Name can only consist of letters, periods(.), commas(,) and spaces"); return false; The problem occurs when it validates the phone numbers. When a valid number is entered, it will not move to the next else-if statement to validate the name. It's been years since I program in Java/C, so I'm a bit rusty. Any help is appreciated. -Alex Hi I need help to finish this code with using nested if statements A price of a ticket to a passenger will be: First Class 500 Economy Class (with meal) 400 Economy Class (without meal) 200 How I can write a JavaScript code according to the following specifications: a. Read the class that the passenger wants to travel on. b. If the class is the first class, print the price of ticket. c. If the class is the economy class, ask the user if he/she wants a meal on the flight. Then print the price of the ticket according to the response of the passenger. The program should simply accept one possible strings the user enters; it is not required to work for all possible inputs such as First, first, FIRST or Yes , yes, YES. This is the code which I have been trying { var inputNum = prompt("Enter the class you want\n first class?\neconomy? :"); if (isNaN(inputNum)) { if (inputNum.match(/first class/)) { document.write("<h1><center>your Ticket is 500<\center><\h1>"); } else { prompt("<h1>if you want a meal on the flight press OK <\h1>"); document.write("<h1>your ticket is 400<h1>,"); } } |