JavaScript - Is It Just Me, Or Is Javascript Annoying To Deal With?
I don't understand why this trivial code won't work. I tried to write my own function to handle key events. Looking at w3schools, it seemed there was nothing to it. So I wrote my function, set up the listeners, and it didn't work. O-O
So after some tinkering w/ my own code, I figured I HAD to be doing something wrong. So I checked someone elses code on the web, and his doesn't work either. html: 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>Untitled Document</title> <script type="text/javascript" src="js/js.js"></script> <link rel="stylesheet" type="text/css" href="css/css.css" /> </head> <body onkeypress="captureKey(event);"> </body> </html> js: Code: function captureKey(e) { if (e.keyCode) { keycode=e.keyCode; // works with the DOM } else { keycode=e.which; // Netscape compatible } move = String.fromCharCode(keycode); alert(move); } I know that javascript is enabled because the tut that I pulled this code from works for me...it's just that the stuff I write doesnt work. I never have these weird problems except with javascript... Similar TutorialsHello, Im hoping someone can help me, Im trying to pass fields to a javascript function that will check the value of each field and it its empty then it will turn the field color red which is what its doing at the moment, but i want to be able to use this function globaly through out my project, so is there a way of not saying how many fields go in to that array, it will just deal with the amount of fields it gets passed? Thanks Hi, On my website, I have one of those trust seals that opens a new window to display account details. Last week it worked fine, but today it is not working. I am sure that I didn't change the code. It still works in IE but the Mox Firefox window opens with no address. This is my js code for the new window: Code: <script language="javascript" type="text/javascript"> <!-- var win=null; function NewWindow(mypage,myname,w,h,scroll){ LeftPosition=300; TopPosition=150; settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes'; win=window.open(mypage,myname,settings); if(win.focus){win.focus();}} function hidestatus(){ window.status='' return true } if (document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT) document.onmouseover=hidestatus document.onmouseout=hidestatus // --> </script> And this is my HTML Code: <!-- // SF-Code Affiliate Marketing ##ak18d54kt** // --> <a href="http://www.support-focus.com/check.php?key=SFM64912" onclick="NewWindow(this.href,'','860','700','yes','default'); return false" onfocus="this.blur()" > <img src="http://www.support-focus.com/image_load.php?id=SFM64912" alt="Support-Focus Membership Click to Verify - Before you Buy" border="0" ></a><br><br> The actual trust seal code appears at the bottom of ths page: Affiliate Marketing test page Can anyone see any problems with the code ? I think I did get a firefox update about a week ago has anyone noticed any changes ? ( I hope its just my code that is wrong ) Oh BTW if I just enter the link from the trust seal directly into the browser, it opens fine. Thanks Hello, I have generated a simple RSS feed javascript to display the last three played tracks from Last.fm on my webiste. Everything works fine, however, there's one annoying detail: There's a tiny little white dot present just after the list is displayed, how can I get rid of this? Hey, I am using an RSS scroller to show recent news feeds I am also using Ajax to change the content from page to page, but instead of using ajax to load the external page for the 'news page' (the image above is the home page) I've had to use a show/hide DIV tool as it refused to load the javascript from the external page. All is working fine apart from text overlay. This is the news page: Code: <script language=javascript type='text/javascript'> function hidediv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){//if they are 'see' divs if (document.getElementById) // DOM3 = IE5, NS6 divs[i].style.display="none";// show/hide else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'none'; else // IE 4 document.all.hideshow.divs[i].display = 'none'; } } } function showdiv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){ if (document.getElementById) divs[i].style.display="block"; else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'block'; else // IE 4 document.all.hideshow.divs[i].display = 'block'; } } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> </head> <body onload="show_clock()"> <div id="wrapper"> <div id="header"> <a href="#" rel="nofollow" target="_parent">Planet Volume</a> </div> <div id="menu"> <ul> <li><a href="#" onclick="javascript:showdiv('newsbox'); javascript:hidediv('newspage'); ajax_loadContent('news3','external/home.html');return false">Home</a></li> <li><a href="#" onclick="javascript:hidediv('newsbox'); javascript:showdiv('newspage'); ajax_loadContent('news3','external/news.html');return false">News</a></li> <li><a href="#" onclick="javascript:hidediv('newsbox'); javascript:hidediv('newspage'); ajax_loadContent('news3','external/request.html');return false">Request</a></li> <li><a href="#" onclick="javascript:hidediv('newsbox'); javascript:hidediv('newspage'); ajax_loadContent('news3','external/contact.html');return false">Contact</a></li> <li><a href="#" onclick="javascript:hidediv('newsbox'); javascript:hidediv('newspage'); ajax_loadContent('news3','external/tunein.html');return false">Tune in</a></li> <li><a class="last"><script language="javascript" src="javascript/liveclock.js"></script></a></li> </ul> </div> <div id="main"> <div id="content"> <div class="content_box"> <div id="mainContainer"> <div class="news" id="news3"> Loading news. please wait... </div> </div> <script type="text/javascript"> ajax_loadContent('news3','external/home.html'); </script> </div> <div id="newspage" style="display: none; visibility: visible;"> <table width="600" style=""> <tr> <td> <h5>Celebrity Gossip</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("celeb-rss", "celeb-rss", 3000, "_new") cssfeed.addFeed("Celebrity", "http://news.feedzilla.com/uk/headlines/celebrities/top-stories.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(4) cssfeed.init() </script> </td> <td> <h5>Music News</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("music-rss", "music-rss", 3000, "_new") cssfeed.addFeed("Music", "http://news.feedzilla.com/uk/headlines/music/top-stories.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(4) cssfeed.init() </script> </td> </tr> <tr> <td> <h5>Movies Reviews</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("movies-rss", "movies-rss", 3000, "_new") cssfeed.addFeed("Movies", "http://news.feedzilla.com/uk/headlines/entertainment/movies-reviews.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(4) cssfeed.init() </script> </td> <td> <h5>Technology</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("tech-rss", "tech-rss", 3000, "_new") cssfeed.addFeed("Technology", "http://news.feedzilla.com/en_us/headlines/technology/top-stories.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(4) cssfeed.init() </script> </td> </tr> </table> </div> <div id="newsbox" class="newsclass" style="visibility: visible; position: absolute;"> <h2>Latest News</h2> <h5>Celebrity Gossip</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("home-celeb-rss", "home-celeb-rss", 4000, "_new") cssfeed.addFeed("Celebrity", "http://news.feedzilla.com/uk/headlines/celebrities/top-stories.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(3) cssfeed.init() </script> <div class="clear h40"> </div> <h5>Music News</h5> <script type="text/javascript"> var cssfeed=new gfeedpausescroller("home-music-rss", "home-music-rss", 4000, "_new") cssfeed.addFeed("Music", "http://news.feedzilla.com/uk/headlines/music/top-stories.rss") //Specify "label" plus URL to RSS feed cssfeed.displayoptions("date") //show the specified additional fields cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag cssfeed.filterfeed(10, "date") //Show 10 entries, sort by date cssfeed.entries_per_page(3) cssfeed.init() </script> <a href="#" class="float_r" onclick="javascript:hidediv('newsbox'); javascript:showdiv('newspage'); ajax_loadContent('news3','external/news.html');return false">More news...</a> </div> </div> <!-- end of content --> This problem only happens for a few seconds, then it scrolls and the news looks fine. It gets very annoying. If you could help me with this dilema I will be very great full! Thanks alot. HI everybody! I am working on a forum, which recently shows a popup window on every single visit. It mainly appears on mobile devices. I have read through the source code, but I don't find the code that shows the popup. Could anyone please have a look at the source and tell me where I can find the code that encodes the popup window? That would be most helpful to me! HERE the link to the website! Any help would be much appreciated! Hi, this will sound stupid, because it is, but i was browsing reddits creepy subreddit, and there was a post (This website's description on Google... : creepy) that was about a creepy site with some ambiguous text, i pressed the link in the comments and got to the site, when i went back, i kept seeing a smudge but only on the reddit creepy subreddit on the screen, idk how this is possible, i've never seen it before, and its on all devices that are connected to the same router, they all get that smudge, so do you guys know any possible ways to fix this? the site is (Krakl) and deleting cookies, cache, restarting etc didnt help, and that smudge is really annoying. tldr; visited site, got smudge trough a script on other site, i see it on other pcs connected to the same internet too. How to remove this, could my pc be infected or something, is this XSS? Sorry, i know that no one here is probably used to this, but i just about exhausted every single option with no results and i want to know whats causing this. Reply With Quote // I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? I have a calendar I made myself. What I want is to open it in a new window, each date is a link, when clicked the date is returned to the original page. How do I do that?? I have searched and found that it is not to hard to make the calendar to open in a new window, but how do I fix the date to be passed along on click?? Yeah, forgot to say I want the date to be returned to a form field... I am new to this forum and new to JavaScript. I am currently taking a class called Web Systems, and for one of the assignments, we need to create a Web page that allows a user to enter a number into a text box, click on a button to calculate shipping, and have a window pop up with the total. There are specifications, but those are not my problem. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Calculate the Shipping</title> <script type = "text/javascript"> /* <![CDATA[ */ var price = document.shipping.purchPrice.value; var total; function calculateShipping(shipping) { if (price <= 25) { total = price + 1.5; window.alert("Your total is: $"+ total); } if (price > 25) { var shipHand = price * 0.1; total = price + shipHand; window.alert("Your total is: $"+ total); } } /* ]]> */ </script> </head> <body> <form id="shipping" method="get" action=""> <label>Purchase Price: </label><input type="text" name="purchPrice" value=""><br> <input type="button" name="shipHandling" value="Calculate Shipping and Handling" onclick="calculateShipping(this.shipping)"> </form> </body> </html> The alert windows will not pop up. I tried listing the code outside of the if-else statement, but then the total becomes undefined. I have been working at this for a day now. I want to be able to understand my mistake, here, so if someone would be able to explain it to me on a very basic level, I would appreciate it greatly. |