JavaScript - Need Help Figuring Out Logic
I was going through LinkedIn today, when I noticed something that I couldn't figure out, logic-wise.
When you search using their search feature at top left, results come up live... no big deal, easy enough, keyup, no biggie. When you click outside the input box, it disappears, which is blur. However, if you click out of the input onto the search results, it remains, and stays up until you click somewhere outside of the input box or the search results. This I have no idea how is done. Is there a way to know what element a user clicks on? Anyone have thoughts/guidance for this? I'm using jQuery as a framework if that helps? Similar TutorialsHi, I am trying to figure out how the get the featured area at http://blueoceanportfolios.com to link to webpages rather than displaying it within the featured box on the left . This area is using JS file to display the videos on content in the featured box when different items on the menu are clicked, here is the working example : http://www.blueoceanportfolios.com/company/ Okay , The problem: Loading a new webpage rather than displaying the content at featured box at http://blueoceanportfolios.com Tried solutions: linking to javascript functions like onclick="window.location="http://someplace.com";" etc but still the content loads up in the featured box , try clicking on 2) it displays http://www.codingforums.com rather than loading new page. Any suggestions I am working on converting something and this is what I have come up with: http://www.msnsportsnet.com/content/ravenstest.htm However, the width of that is 845 px and I wanted it to drop down to 650 px and make the arrows have the same effect as they did with the 845 px. First I moved the 845 to 650 in the css file, then changed the 845 to 650 in the JS files, I have been unable to figure this out though. If someone could please help that would be great! This is the JS file that I tried to edit: http://www.baltimoreravens.com/includes/jsbin/ravens.js This is the css file: http://www.msnsportsnet.com/content/ravens.css Hi guys, I need some help. I'm trying to make a banner in java or jquery. Idea is div 1 div 2 div 3 div 4 >> custom div1 button >> custom div2 button >> custom div3 button >> custom div4 button I've also added an image of something i have in mind... i can do the CSS but i can't figure out a good tutorial. The closest I found on google was this http://cssglobe.com/lab/easyslider1.7/02.html but its with numbers.. Hi I am attempting to use a javascript code that ultimately shows a live video feed. The affiliate site that created the code says when they pull up my website page with the code on it, they can see it. My problem is, I cannot, no matter what browser I use. Firefox 10.5, IE9, and Chrome all are set to enable javascript. I'm using Windows Vista Ultimate. I am also using a premium Wordpress theme. I contacted the theme creator and on the support forum there, he was able to see the code working just fine also so I determined it is indeed a problem local to my own settings but I am stumped. I googled and set my browser settings to make sure javascript is enabled in all of them. I run Kaspersky antivirus; I tried disabling my firewall, no dice. I ran malwarebytes, that didn't help either. EVERYTHING on my pc is up to date, this has really got me stumped. I know I'm missing something; just can't figure out what I also admin a second site using the same WP theme so I tried it there as well, still can't see it. I so appreciate any suggestions. Thank you so much for your time Hello, What I need is a simple service area, zip code validation form that redirects to a certain URL when a valid zip code is submitted and a different URL when an invalid zip code is submitted. I found a form script example that works well with only a single zip code. My problem is I can't figure out how to modify it so that multiple zip codes are valid. Here is the head part. 60016 is one of about 50 valid zip codes I need the form to accept as valid - [code] <script> var correctCode = "60016"; function validateCode() { var code = document.getElementById("codeTextBox").value; if (code == correctCode) { window.location.href = "/ggc/test1"; } else { window.location.href = "/ggc/test2"; } } </script> [code] Here is the body part - [code] Please enter your zip code: <input type="text" name="codeTextBox" id="codeTextBox" /> <input type="submit" name="Submit" value="Submit" onclick="validateCode()" /> [code] Hey friends, I'm writing a program but I'm having issues. I need to write a program that asks for 3 different numbers (prompt boxes) and determine which number entered was the highest and the 2nd highest. I know what to do for the input and output but I don't know what to do during the processing.
im trying to add the following numbers: 0+1+2+3+4. The actual answer being 10 obviously. i dont realy get why its coming out as 5 and not 10. Code: var sum = 0; for (i = 0; i < 5; i++); { sum = sum + i; } document.write("Sum is: " + sum); How can we identify logical errors from other types of errors?
Hello everyone. I need some guidance on what might be the best way to tackle this problem. I am creating a page for work. It is a local html site that will be used to show different "questions" in the form of a number of different <div>'s. Currently, the page is set up to have two initial questions that are always visible. The first question asks the user to select from 9 checkboxes and the second asks to choose between 7 radio buttons. Choosing both calls on an onclick javascript event called setup page. This is where I need the help. There are currently 25 hidden <div>'s on the page. The premise is that, depending on your answers to the first two questions, some of those 25 divs become visible for the user to answer those questions only. Currently, when that setup page onclick event is called, the setup page function goes through each of the 25 questions and says Code: pseudocode: if q1_a.checked || q1_b.checked && q2_a.checked, show question 3 div if q1_c.checked && q2_b.checked, show question 4 div etc... I'm thinking there's got to be a better way. This page is becoming unruly and hard to troubleshoot with so much javascript/variables. I was thinking about using case statements but with so many variable options between those two first questions I think there would be too many cases. Any suggestions on another way I can go about this? Thanks!! Putting some javascript into a pdf file and can't get this to work out right. Basic setup: Field X = checkbox; Field Y = numeric input field; Here's what should happen (increment is toggled): Y has a value. When X is checked, Y is increased by 5. When X is unchecked, Y goes back to its original, unmodified value. Here's what really happens (increment is subtracted): Y has a value. When X is checked, Y is reduced by 5. When X is unchecked, Y is reduced by 5 again. Anytime X is clicked on, Y is reduced by 5 yet again. Here's the code: Code: function check_box(X, Y){ if(X.checked == true){ Y.value += 5; } else { Y.value -= 5; } Any help or advice is greatly appreciated. In my previous post, I asked how to create a function that would allow me to add to or subtract from a maxvalue, and thankfully I got help regarding that. However, something's got me stumped for the past few weeks that I still can't resolve... This is the relevant code: Code: <html> <head> <script type="text/javascript" language="Javascript"> function chgAdv(btn) { var form = btn.form; var newqty = parseInt(btn.value); var maxqty = form.maxqty; var maxadv = form.maxadv; if (eval("btn.checked") == true && parseInt(maxadv.value) + newqty <= 15) { var newmax = parseInt(maxqty.value) - newqty; var newadv = parseInt(maxadv.value) + newqty; } else if (eval("btn.checked") == false && parseInt(maxadv.value) - newqty >= 0) { var newmax = parseInt(maxqty.value) + newqty; var newadv = parseInt(maxadv.value) - newqty; } else { var newmax = parseInt(maxqty.value); var newadv = parseInt(maxadv.value); } if ( newadv >= 0 && newmax >= 0) { maxqty.value = newmax; maxadv.value = newadv; } } function chgDis(btn) { var form = btn.form; var newqty = parseInt(btn.value); var maxqty = form.maxqty; var maxdis = form.maxdis; if (eval("btn.checked") == true && parseInt(maxdis.value) + newqty <= 10) { var newmax = parseInt(maxqty.value) + newqty; var newdis = parseInt(maxdis.value) + newqty; } else if (eval("btn.checked") == false && parseInt(maxdis.value) - newqty >= 0) { var newmax = parseInt(maxqty.value) - newqty; var newdis = parseInt(maxdis.value) - newqty; } else { var newmax = parseInt(maxqty.value); var newdis = parseInt(maxdis.value); } if (newdis >= 0 && newmax >= 0) { maxqty.value = newmax; maxdis.value = newdis; } } </script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <form name="f1"> <b>Advantages</b> (<input type="text" class="RO" name="maxadv" value="0" />)<br /> <input type="checkbox" class="RO" name="Absolute Direction" onclick="chgAdv(this);" value="2" />Absolute Direction<br /> <input type="checkbox" class="RO" name="Allies" onclick="chgAdv(this);" value="3" />Allies<br /> <hr> <b>Disadvantages</b> (<input type="text" class="RO" name="maxdis" value="0" />)<br /> <input type="checkbox" class="RO" name="Antisocial" onclick="chgDis(this);" value="2" />Antisocial<br /> <input type="checkbox" class="RO" name="Ascetic" onclick="chgDis(this);" value="4" />Ascetic<br /> max quantity: <input type="text" readonly class="RO" name="maxqty" value="40" /> </form> </body> </html> styles.css is simply: Code: input.RO { border: none; width: 40px; text-align: center; } As it stands, it works as long as the total value is less than or equal to the limit (for advantages it's 15, for disadvantages it's 10). However, the moment it goes past the limit -- for instance, if you change Antisocial's value from 2 to 7, or if you add several additional checkboxes with any values -- the whole thing starts going crazy; specifically, maxvalue doesn't revert to 40 when the all the checkboxes are unchecked. What I'd want to happen is that the user cannot select or apply advantages or disadvantages if the maximum advantage is greater than 15 or the maximum disadvantages is greater than 10. I'm thinking that a button for adding disadvantage points to/subtracting advantage points from the maxvalue (that becomes disabled if the user goes past his limit on advantages/disadvantages) is useful at this point, but I'm really stumped on the implementation of the idea. An alternate idea of mine is that all other advantage/disadvantage checkboxes would become disabled if their value is greater than the remaining number of points, but I don't know how that is possible either. Any and all help is greatly appreciated. Hello all, As this is an active javascript programming forum...i'm really hoping i'll get a solution for my problem...please help me out.... I have a html: text inside a logic:iterate block like this.. <logic:iterate name="AllocationsForm" property="newSearchAllocations" id="allocations" indexId="myindex" > <html:text name="allocations" property="newStartDate" indexed="true" onblur="allocationTest(this, " + myindex + ");" /> </logic:iterate> i want to write a onblur event for this text field inorder to validate it. Is it the correct way i wrote or something i need to make a change in the above code inorder for the javascript to work. Can we really able to write a onblur event for a indexed text field that is inside a logic:iterate block. please let me know. Thanks in advance. was wondering if it made sense to optimize the comparison order inside an if() statement if one of the comparison targets is a function call eg: Code: var a = true, b = function() {return false;}; if (b() || a) {...} if (a || b()) {...} would the second statement run faster because it would theoretically never need to call b() in this situation? can the eval order be relied on? does this depend on the js engine/internal optimizations? thanks, Leon Hey there. I'm creating my web-site now. I'm planing to have some slide/object change by itself. I know Java Script perform this task. I have get the code and apply to the image I want. It works. My idea is each of my image upper left corner have the representative number of the slide. When the slide1 go to slide 2 automatically, the number will change colour from 1 to 2. When the user click the number, the slide will change according to the number. Let said I have 3 slide. Each slide and have no 1 ,2 ,3 move forward, move backward icon on the upper left corner. I have slide1 ,slide2, slide3 change by itself within 2.5 second. When the user go thru slide 1, slide 2 and till slide3, user find out he/she interested on slide 1 and by clicking 1 on the upper left corner, the slide will change back to slide 1. Something like showing on the home page at www.easyjet.com.EN or http://www.thomascook.com/ . Both home page show a slide. This is what exactly I want. I learn HTML code before but not Java Script. I have borrow many Java Script reference book. but no idea how to inside the number on the upper left corner on each slide and how the number work accordingly with the slide. So sorry if you can't understand what I was talking about. But, anyone who understand me or have any idea how can I mortify the Java script to what I want. Just answer or email me to trista_soo@yahoo.com or facebook me on sym107@hotmail.com. Thanks for your time and efforts. Your help I really appreciate. Cheers! Hi, I am using a wordpress jquery based plugin. TheThe Sliding panels. You can see the jquery he - http://www.get-me-heard.com/wp-conte...jquery.ttsp.js The panel currently auto-opens when the page loads. Which is what I want, however I would like it so that once a user has clicked to close the panel, for it to stay closed even when navigating pages, until they decide to click open again. I would also need the cookie flushed when they leave the website so that the next time they return the panels auto open again. Essentially I just dont want the users to have to click close every time they navigate throughout the website if they don't want to see the panels. NOTE: The plugin has several panels which you can choose from. I am only using the left panel and the right panel. They are all controlled within the jquery. Thanks! I don't understand the logic of Break, Return False, Return True. It was never really covered in our college class, and I see everyone using it. I got an A in the class, if that 'proves' that I really tried to apply myself. NOTE: I understand what the function is doing. I just don't understand WHEN to use break, return false or return true if the the translator can determine the conditional statements. PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } else return false; } if the the translator can determine the conditional statements, why not write it like this: PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; // what's the point for the 'break'? Won't the rest of the code be ignored since it passed the first condition? } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } // why not leave the last else out? is it just a 'safety' catch, in case something other than true or false is inputted? else return false; // what's the point? } Questions: Why use return true, if the translator knows it's ture? Why use "return false" if the translator knows it's false and the alert window has already gone up? why not use "break" to stop the code? Why use the "return false" at the end "else" statement? |