JavaScript - Quick Name Conflict Question
can I have a function and a variable be the same name in an object
for instance Code: function someObject(){ this.canDoSomething;//a boolean variable function canDoSomething(){ //set this.canDoSomething; return this.canDoSomething; } } or will this be a naming conflict? thanks Similar TutorialsUrghh I've always done it this way but it's nagging me. Is there a better way of checking if a value is equal to 1 or 2 or 3 than doing it this way. Code: if(var === Cat || var === Dog || var === Chicken || var === Frog) Not working code ^ lol Cheers guys Was wondering if someone could help me quickly, i'm have a strange issue with a slideshow i have built in javascript. The slideshow works fine until you add any other image onto the page like a banner or anything. As soon as you do that when you click next on the slideshow that image or banner with change to the next picture instead of the desired image if that makes any sense... Would appreciate any help, thank you! here is the link to my practice website, so you can see what is going on pretty new to all of this.. http://dpetersen.net46.net/advancedw...l.html?agree=0 I found this "game" that helps you practice regexp. I'm stuck on this one: I put the jquery script into my subdirectory. In the header which one is correct: Code: <script type="text/javascript" src="../jquery/jquery.js"></script> or Code: <script src="../jquery/jquery.js"></script> And there is this code: do I put this in the body and enclose it with the <script>tag? Code: $(function(){ // set interval for 5 minutes setInterval(function(){ $.ajax({url: "keep-alive.php"}); }, 300000); }); using jquery and cookie plugin. i made a popup window. when the user clicks on a check box the window closes, forwards them to a new page, and then sets a cookie. i need it so that when they go back to the original page (where the popup came from) if the browser detects the cookie then the popup does not occur. I do not know why this does not work because when I alert the value of the cookie out, it gives me the correct number. something must be wrong in my logic ? code on the base page. Code: <script type="text/javascript"> var test123 = $.cookie('FBCheck'); if ( test123 != 1212){ function popup(Site) { window.open(Site,'PopupName','toolbar=no,statusbar=no, location=no,scrollbars=no,resizable=no,width=350,height=500') } } </script> code on popup (both files are in same directory) Code: $(document).ready(function() { $("#Cbox").click(function() { window.open ("http://www.google.com", "Google"); window.close(); $.cookie('FBCheck', '1212', {expires: 365, path: '/'}); }); }); The jquery source is installed as is the plugin. Thanks so much for your help in advance! Hey everybody! I am trying to do a simple echo onclick, but despite what I try to do, it shows no errors, but won't work. I've tried things like: Code: echo "<div onclick=\"alert('test');\">t</div>"; echo '<div onclick="alert(\'test\');">t</div>'; But just can't seem to get it to work right. I'm trying to do this on a script that is being eval on the ajax request. Thus I'm having problems placing the ',", \ marks. Thanks for your time. Hi, Ever seen on the iphone where you have to slide the slider across the screen to unlock it? I have a duplicate of this using javascript but no matter what I try I cannot make it redirect. I want the page to be redirected after the slider has gone to the other side. Heres the HTML Code: <!DOCTYPE html> <head> <meta charset='UTF-8'> <title>Slide To Unlock</title> <link rel='stylesheet' href='css/style.css'> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script> <script src='js/slidetounlock.js'></script> </head> <body> <div id="page-wrap"> <div id="well"> <h2><strong id="slider"></strong> <span>slide to unlock</span></h2> </div> </div> </body </html> And the javascript Code: $(function() { $("#slider").draggable({ axis: 'x', containment: 'parent', drag: function(event, ui) { if (ui.position.left > 550) { $("#well").fadeOut(); } else { // Apparently Safari isn't allowing partial opacity on text with background clip? Not sure. // $("h2 span").css("opacity", 100 - (ui.position.left / 5)) } }, stop: function(event, ui) { if (ui.position.left < 551) { $(this).animate({ left: 0 }) } } }); // The following credit: http://www.evanblack.com/blog/touch-slide-to-unlock/ $('#slider')[0].addEventListener('touchmove', function(event) { event.preventDefault(); var el = event.target; var touch = event.touches[0]; curX = touch.pageX - this.offsetLeft - 73; if(curX <= 0) return; if(curX > 550){ $('#well').fadeOut(); } el.style.webkitTransform = 'translateX(' + curX + 'px)'; }, false); $('#slider')[0].addEventListener('touchend', function(event) { this.style.webkitTransition = '-webkit-transform 0.3s ease-in'; this.addEventListener( 'webkitTransitionEnd', function( event ) { this.style.webkitTransition = 'none'; }, false ); this.style.webkitTransform = 'translateX(0px)'; }, false); }); So i have this algorithm and im not sure how to translate it into javascript if (the Round Trip button is checked) double the fare my fare calculated works correctly based on the distance traveled, but how do i make it so that when round button is checked the fare gets doubled, im not quite sure how to make that a code i have a program where a user enters a temperature in farenheit and the program converts it to celcius. below is my code: Code: <html> <head> <title>JavaScript Assignment 4 Part 1</title> </head> <body> <h2>Welcome to the Temperature Calculator!!</h2> <script type="text/javascript"> var fTemp; var number1; var cTemp; fTemp = window.prompt( "Please enter temperature in Farenheit:", "0" ); number1 = parseInt( fTemp ); cTemp = (5/9) * (number1 - 32); document.writeln("The corresponding temperature in Celcius is: " + cTemp); </script> </body> </html> what i cant figure out is how to round off the temperature in celcius so that it doesnt display something like 26.666666666667 i tried putting math.round in "cTemp = (5/9) * (number1 - 32);" but when i do my program doesnt work any advice on how to go about doing this? thanks Hi guys, just a quick question about a line break in JavaScript, where would I do it? If you see I have two math operators here and want them to be on two separate lines, were do I put the line break? Thanks Code: <!doctype html> <head> </head> <body> <script type="text/javascript"> var apples = 4+76; document.write(apples); var multiple = 54*11; document.write(multiple); </script> </body> </html> Here is what i'm trying to do and I'm not sure if it will work with a switch, but i'd be better than writing a million if else statements. Code: var = c var = z switch (c) { case c > 1 && < 10: z = 5; break; case c > 10 && < 20: z = 15; break; default: z = 0; } I think you see what I'm trying to do. I have a variable 'c' and it is input by the user and I want to make variable 'z' set according to what 'c' is. I know the above code doesn't work, but I'm not sure why. I've tried a million different things to try and get it to work, but it always just goes to default when it displays 'z'. Any help would be great. Thanks. I have a simple issue that I cannot fix. The code bellow, is a while-loop with RGB color. It displays the word Hello 10 times id 10 different colors. The problem is I cannot get the correct colors displayed. I want the first Hello to be red and end up green in the last one. For some reason I cannot get the color combination correct, even after I put 255 for red and 192 for green. Can you please have a look and tell me what am I doing wrong? Thanks in advance 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>Project 4 - Exercise 10</title> </head> <body> <script language="JavaScript"> var r = 254; var g = 254; var b = 125; for (i=1; i <= 10; i++) { document.write ("<font size=7 color = rgb(" + i + "," + g + ", "+b+")> Hello <br>"); } </script> </body> </html> Is it possible to have an input that points to some other function? For example: Code: function someFunction() { alert('It worked.'); } function doAnotherFunction(doIt, otherFunction) { if (doIt == true) { otherFunction(); } } <input type="button" value="test" onClick="doAnotherFunction(true, someFunction());"> Or would I need a switch statement and have all the various functions hardcoded? Code: var str = "12:34pm blah blah blah...", timeTrim = str.match(/\d{1,2}:\d{2}(pm|am)\s/); document.write(timeTrim); //12:34pm ,pm Why does it match "pm" twice? function get_price() { var the_price=1000; if (this.speed=="500MGz") the_price+=200; else the_price+=100; if (this.hdspace=="15GB") the_price+=50; else the_price+=25; if (this.ram=="128MB") the_price+=150; else the_price+=75; return the_price; } function computer(speed,hdspace,ram) { this.speed=speed; this.hdspace=hdspace; this.ram=ram; this.price=get_price; } var work_computer=new computer("2GHz","80GB","1GB"); var home_computer=new computer("1.5GHz","40GB","512MB"); var laptop_computer=new computer("1GHz","20GB","256MB"); var work_computer_price=work_computer.price(); var home_computer_price=home_computer.price(); var laptop_computer=laptop_computer.price(); ___________________________________________________ In the above code, the line I'm having trouble with is marked red. Why is it that when I call the method using ... this.price = get_price; It works fine. But if I assign the object this.price with like this... this.price = get_price(); I get an error? Isn't get_price() a function? So shouldn't the parenthesis be included when the method is called? Why are we suppose to leave out the parenthesis?! I'm confused. Thanks! Is it possible to give an anchor tag an id and call it with GetElement? this is what I have tried: Code: <a id="link1" href="test.html">Part 1</a></li> Code: document.getElementById("link1").style.color = "blue"; This is my CSS: Code: A:link { color:#ffffff; font-size:14pt; font-weight:bold;} A:visited { color:#ffff00; font-size:14pt; font-weight:bold;} A:hover { color:#6698ff; font-size:14pt; font-weight:bold;} A:active { color:#c0c0c0; font-size:14pt; font-weight:bold;} I need to change the source of an image but I can't seem to figure out how. I believe that I have the correct syntax, but it does not seem to be working. Maybe I am typing it in wrong or something. I try to test my javascript by typing the script: <strong>javascript:document.getElementById('img1').src='./images/image1.jpg';</strong> into the address bar. Nothing happens. I also try to test it out by putting this on the page, but once again, nothing happens. Code: <script type="text/javascript"><!-- document.getElementById('im1').src="./scripts/'.$upload_image.'"; //--></script> This is what my HTML code looks like: Code: <img src="./images/temp_wizard_picture.gif" alt="" style="padding:4px; background:#fff; border:1px #bbb solid;" id="img1" /> Can somebody please fill me in on what I am doing wrong. Thank you. Hi Guys. I wish I could say I was a fellow coder but I'm not. I am a WYSISYGer that promised to help a friend and is lost. I'm making her a site that is based on a js template. I want to add a lightbox effect using jquery. Ive been trying to use a plugin called bumpbox because unlike lightbox it allows static html in the popup. When I implement the plugin in a very basic html doc, it works just fine. However when I use it in my js site, nothing happens. I really really don't understand what I am doing right or wrong, so if someone could take a look at code and help me out (with very basic instructions), I'd really appreciate it! Ive uploaded site to http://www.flashfollow.com/index.html click home>link saying seo it should open a lightbox...currently to developers site. THANKS SO MUCH Heya there, I have been trying to run two Javascripts within the same page. The first is the Drop down menu Javascript, the second is the Picture Viewer (Click an image and it opens) Here is a copy of the webpage (the active version has been modified to reduce confusion for users) http://f1p.co.uk/saved%20pages/picture1.html I have tried a noconflict, but it didn't seem to work. As you can see, the Picture viewer works fine, but the drop down menu seems to be in conflict. Any help please? Howdy all, I have changed same function names, and have incorporated both maps in bodyOnload, but they are still conflicting. Map 1 works fine. Map 2 shows up, but doesn't change it's images at all onmouseover. You won't be able to test it, but I'm hoping someone can spot a conflict in the code structure. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </script> <SCRIPT type=text/javascript> // map # 1 var isLoad = false; var pic0 = null; var pic6 = null; var pic7 = null; var pic8 = null; var pic9 = null; var pic10 = null; var pic11 = null; var pic12 = null; var pic13 = null; function preLoad() { // state maps pic0 = new Image() pic0.src="mapsv2/00_state_00.gif" /*pic1 = new Image() pic1.src="mapsv2/00_metro_01.gif" pic2 = new Image() pic2.src="mapsv2/00_metro_02.gif" pic3 = new Image() pic3.src="mapsv2/00_metro_03.gif" pic4 = new Image() pic4.src="mapsv2/00_metro_04.gif" pic5 = new Image() pic5.src="mapsv2/00_metro_05.gif"*/ pic6 = new Image() pic6.src="mapsv2/00_metro.gif" pic7 = new Image() pic7.src="mapsv2/00_state_07.gif" pic8 = new Image() pic8.src="mapsv2/00_state_08.gif" pic9 = new Image() pic9.src="mapsv2/00_state_09.gif" pic10 = new Image() pic10.src="mapsv2/00_state_10.gif" pic11 = new Image() pic11.src="mapsv2/00_state_11.gif" pic12 = new Image() pic12.src="mapsv2/00_state_12.gif" pic13 = new Image() pic13.src="mapsv2/00_state.gif" pic14 = new Image() pic14.src="mapsv2/00_state_06.gif" isLoad = true; } function changeImage(mFileName) { if(isLoad) document.statemap.src = mFileName.src; } </SCRIPT> <script type =text/javascript> //map #2 var isLoaded = false; var pic1 = null; var pic2 = null; var pic3 = null; var pic4 = null; var pic5 = null; var pic6 = null; function preLoadOne() { // state maps pic1 = new Image() pic1.src="mapsv2/00_metro_01.gif" pic2 = new Image() pic2.src="mapsv2/00_metro_02.gif" pic3 = new Image() pic3.src="mapsv2/00_metro_03.gif" pic4 = new Image() pic4.src="mapsv2/00_metro_04.gif" pic5 = new Image() pic5.src="mapsv2/00_metro_05.gif" pic6 = new Image() pic6.src="mapsv2/00_metro.gif" isLoaded = true; } function changeImg(pFileName) { if(isLoaded) document.metromap.src = pFileName.src; } </script> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> </head> <body> <meta name="robots" content="noindex,nofollow"> </head> <body onload="preLoad();preLoadOne()"> <h1> " "</h1> <img src="banner_crest.gif" alt="crest logo"><br> <!-- Map # 1 --> <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> <TBODY> <TR> <TD class=pageDesc colSpan=2> <P><IMG height=400 src="mapsv2/00_state.gif" width=355 useMap=#mainmap border=0 name=statemap> </P></TD></TR></TBODY></TABLE> <div id="page"> <div id="map_section"><MAP name=mainmap> <!--state_im_Map --> <AREA onmouseover=changeImage(pic0); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Metro & Hills" COORDS="279,281, 275,294, 264,294, 268,276" href="metro.html"> <AREA onmouseover=changeImage(pic14); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Barossa" COORDS="282,268, 278,283, 264,279, 259,267, 275,263" href="section.asp?regionID=06"> <AREA onmouseover=changeImage(pic7); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Fleurieu and Kangaroo Island" COORDS="245,310, 255,314, 242,318, 214,315, 217,310, 242,307" href="section.asp?regionID=07"> <AREA onmouseover=changeImage(pic7); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Fleurieu and Kangaroo Island" COORDS="281,296, 278,301, 275,306, 267,307, 255,305, 279,292" href="section.asp?regionID=07"> <AREA onmouseover=changeImage(pic8); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Eyre and Western" COORDS="145,76, 139,117, 122,120, 131,149, 142,153, 146,157, 167,162, 160,190, 161,196, 173,206, 198,219, 218,226, 234,235, 243,221, 249,221, 247,225, 239,236, 229,248, 209,264, 199,275, 201,278, 199,285, 194,284, 185,274, 187,271, 173,245, 166,229, 155,226, 154,216, 157,211, 147,207, 144,202, 136,197, 127,199, 110,192, 101,195, 72,180, 57,183, 16,183, 15,77" onclick="Populate('list1',EYRE_AND_WESTERN_JUNIOR_PRIMARY)"> <AREA onmouseover=changeImage(pic9) ; onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Far North" COORDS="344,13, 330,225, 312,229, 309,233, 293,230, 289,229, 287,215, 278,211, 272,200, 267,203, 258,212, 253,214, 251,216, 248,213, 245,222, 236,229, 232,235, 223,231, 215,224, 208,221, 198,222, 184,218, 181,214, 172,203, 157,197, 161,190, 166,187, 162,159, 141,154, 137,150, 122,146, 126,116, 144,114, 140,73, 10,74, 10,12, 264,9" onclick="Populate('list1',FAR_NORTH_PRIMARY)"> <AREA onmouseover=changeImage(pic10); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Limestone Coast" COORDS="326,317, 320,385, 307,377, 292,349, 296,339, 296,328, 302,324, 314,314" href="section.asp?regionID=10"> <AREA onmouseover=changeImage(pic11); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Murray and Mallee" COORDS="332,227, 322,314, 314,319, 309,322, 303,326, 292,325, 282,305, 285,301, 277,284, 280,277, 286,267, 294,225, 311,226, 332,224" href="section.asp?regionID=11"> <AREA onmouseover=changeImage(pic12); onmouseout=changeImage(pic13); shape=POLY rel="nofollow" target=_self alt="Yorke and Mid North" COORDS="276,203, 284,214, 289,217, 285,267, 274,267, 257,265, 254,263, 241,291, 222,293, 229,284, 238,280, 245,249, 250,236, 253,230, 253,210, 266,201" href="section.asp?regionID=12"> </MAP> </div> <!--Map #2--> <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> <TBODY> <TR> <TD class=pageDesc colSpan=2> </TD></TR> <TR> <TD class=section colSpan=2><BR> <TR> <TD class=section><BR> <P><IMG height=400 src="mapsv2/00_metro.gif" width=301 useMap=#state_im_Map border=0 name=metromap> </P></TD></TR></TBODY></TABLE><MAP name=metromap> <AREA onmouseover=changeImage(pic1); onmouseout=changeImage(pic6); shape=POLY rel="nofollow" target=_self alt="Eastern Adelaide" COORDS="151,142, 136,158, 139,168, 139,175, 134,177, 129,186, 130,198, 123,194, 118,193, 84,187, 88,169, 90,144, 92,141, 98,143, 118,149, 125,139, 139,138, 152,138" href="section.asp?regionID=01"> <AREA onmouseover=changeImage(pic2); onmouseout=changeImage(pic6); shape=POLY rel="nofollow" target=_self alt="Northern Adelaide" COORDS="138,8, 141,21, 159,31, 177,9, 180,15, 188,25, 185,30, 208,47, 193,92, 174,95, 168,98, 167,108, 167,117, 164,137, 164,142, 150,138, 118,148, 111,150, 107,149, 88,132, 88,121, 79,110, 87,100, 84,88, 45,45, 40,39, 50,27, 62,18, 70,17, 124,12" href="section.asp?regionID=02"> <AREA onmouseover=changeImage(pic3); onmouseout=changeImage(pic6); shape=POLY rel="nofollow" target=_self alt="Southern Adelaide" COORDS="105,191, 118,193, 128,196, 128,204, 129,218, 129,226, 131,227, 136,274, 136,305, 132,323, 111,322, 90,355, 65,376, 41,389, 34,392, 21,389, 29,346, 33,324, 42,256, 57,219, 57,189, 74,192, 84,190" href="section.asp?regionID=03"> <AREA onmouseover=changeImage(pic4); onmouseout=changeImage(pic6); shape=POLY rel="nofollow" target=_self alt="Western Adelaide" COORDS="62,87, 64,88, 66,85, 70,97, 72,101, 67,101, 71,108, 70,110, 91,124, 87,182, 67,195, 52,180, 44,120, 49,102, 48,87, 59,82" href="section.asp?regionID=04"> <AREA onmouseover=changeImage(pic5); onmouseout=changeImage(pic6); shape=POLY rel="nofollow" target=_self alt="Adelaide Hills" COORDS="224,55, 238,63, 253,91, 256,94, 271,97, 286,115, 292,121, 277,133, 278,143, 264,161, 286,182, 283,192, 287,213, 285,260, 284,284, 276,289, 246,281, 237,292, 228,290, 221,296, 209,312, 204,316, 179,323, 173,327, 165,341, 141,332, 135,318, 139,299, 139,292, 129,256, 129,227, 127,221, 129,210, 130,198, 132,195, 131,178, 139,168, 134,158, 144,150, 158,137, 164,141, 166,119, 167,107, 169,99, 172,94, 183,89, 193,90, 198,69, 212,48, 222,56" href="section.asp?regionID=05"> <!--<area shape="poly" href="default.asp" rel="nofollow" target="_self" alt="State Map" COORDS="300,0, 300,400, 0,400, 24,392, 42,388, 87,357, 120,320, 137,327, 165,341, 172,329, 174,326, 187,319, 193,318, 197,316, 204,314, 217,303, 225,290, 235,291, 246,279, 251,276, 272,285, 280,287, 286,270, 284,230, 283,197, 284,183, 283,175, 263,155, 266,150, 275,139, 278,126, 289,117, 275,106, 270,97, 264,95, 252,91, 242,82, 242,79, 241,74, 231,59, 220,56, 214,53, 197,37, 184,29, 184,20, 177,13, 173,10, 153,32, 137,14, 135,6, 111,14, 85,16, 53,25, 36,33, 32,33, 29,15, 10,0"> --> </MAP> </body> </html> Cheers, Tom |