JavaScript - Finding Bugs In Minimized Code
Hi
We have a js heavy web-ui. In the production environment it runs minimized, composed from 10 or so js files. When we have a js-error of some sort (we have about 100 users and growing) we write the window.onerror information to a database. Only, it is not very helpful since linenumbers mean nothing in the intelligeble code. Is there a minifier that tags the result that would allow translation of linenumbers? Is there some other method people use to solve this problem? I did search the forum before and found nothing on this topic. Thanx for any advice /klas Similar Tutorialsnot sure anything wrong with my IE8 browser or 'createTextNode' method. here comes the bug: if you directly do this document.body.appendChild(document.createTextNode(" "+"a")), then there won't be any spaces before 'a' however, if the argument of that method is changed to "a"+" "+"a", this time it will be ok. why it cannot create the leading spaces before any non-whitespace string? thx in advance. I've put together a spoiler bb code, and I've noticed 2 bugs with it - I'm thinking that it's to do with the javascript end of the code. when the code is used, the page has to be refreshed for the spoiler to open and work correctly, also if there is 2 spoilers on the same page, if i click the second one, it opens the first one and not itself. I didn't type the javascript code I only did the html and css end, so I'm not sure what's going on. If any of you can help me I'd be really grateful. Here is the code: Code: <html> <head> <style type="text/css"> body,input { font-family:"Trebuchet ms",arial;font-size:0.9em; color:#333; } .spoiler { color: #494949; font-size: 10pt; font-weight:bold; text-align:left; background-color: #cbeafe ; border-top: 1px solid #9dc2d9; border-left: 1px solid #9dc2d9; border-right: 1px solid #9dc2d9; border-bottom: 2px solid #9dc2d9; padding: 2px; width:90%; min-height:18px; margin: 1px auto 1px auto; -moz-border-radius: 4px; -webkit-border-radius: 4px; -moz-box-shadow:0 0 2px #cbeafe; -webkit-box-shadow:0 0 2px #cbeafe; } .show { color: #00a2c5; font-size: 10pt; font-weight:bold; text-align:center; background-color: #fff ; border: 1px solid #fff; padding: 2px; width:25%px; min-height:5px; margin: 1px auto 1px auto; -moz-border-radius: 2px; -webkit-border-radius: 2px; -moz-box-shadow:0 0 2px #fff; -webkit-box-shadow:0 0 2px #fff; } .hide { color: #00a2c5; font-size: 10pt; font-weight:bold; text-align:center; background-color: #fff ; border: 1px solid #fff; padding: 2px; min-width:25px; min-height:5px; margin: 1px auto 1px auto; -moz-border-radius: 2px; -webkit-border-radius: 2px; -moz-box-shadow:0 0 2px #fff; -webkit-box-shadow:0 0 2px #fff; } </style> <script type="text/javascript"> function hide(id){ document.getElementById(id).style.display = 'none'; } function show(id){ document.getElementById(id).style.display = ''; } function showSpoiler(obj) { var inner = obj.parentNode.getElementsByTagName("div")[0]; if (inner.style.display == "none") inner.style.display = ""; else inner.style.display = "none"; } </script> </head> <body> <div class="spoiler"><img src="http://i.imgur.com/s5tS1.png" align="left"><img src="http://i.imgur.com/6Uq7Y.png" align="right"> <div id="show"><input type="button" class="show" onclick="hide('show'); show('hide'); showSpoiler(this);" value="Show" /> </div> <div id="hide" class="inner" style="display:none;"> <input type="button" class="hide" onclick="hide('hide'); show('show'); showSpoiler(this);" value="Hide" /> <br /><br />{param}<br /></br> </div> </div> </body> </html> Hello there guys! Thanks for taking time to view this thread. It's appriciated! I found a really nice menu (Javascript, JQuery) im not so high tech on this myself, and not the best coder either but whenever I use this menu it gives the login box on the website an error, it doesn't let people login.. I've tried to localize the error myself, but I just dont know how to fix it, I think the issue is that the site system i use doesn't support these type of scripts which gives the login errors! I'm currently using a free website system, which allows you to customize anything you want called "uCoz" The menu i used was: http://www.dynamicdrive.com/dynamici...enu-glossy.htm And I think it's the jquery that gives the login box errors.. I'm thankfull for answers if anyone knows Can anyone direct me to the source of this carousel or something similar? http://www.murdockyoung.com/projects...-house/images/ Thanks in advance! Hi there I have this problem where there is something wrong with the variable scope, but I cannot find it, the first problem I have is that the program doesn't work, and the second is the error with the variable scope. Please can you help me fix it. Code: var count = 0; function gimmeRandom() { var rand = Math.floor(Math.random()*10)+1; count++; } function countToRandom() { for (count = 1; count <= rand; count++) { console.log(count); } } console.log("Counting to a random number"); gimmeRandom(); countToRandom(); console.log("Counting to another random number"); gimmeRandom(); countToRandom(); console.log("There has been "+count+" random numbers"); Reply With Quote 01-13-2015, 10:34 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts Any variable declared (using the var keyword) *inside* a function is ONLY visible inside that function. So your rand variable can NOT be seen, at all, in your countToRandom( ) function. Okay, this should be an easy one. I'm a JS newb, so be kind The code I have right now is an autosuggest feature, but currently, it only finds exact matches, not partials. I want it to find partials. I know the line of code I need to rewrite, but I can't figure out what JS function to use. For example, if a user types "pizza", i want "pepperoni pizza" to show up, not just things that start with "pizza". Code: // str is the string that the user is typing in // this.aNames is an array containing all the possible strings to match against // aList is the list of matches from aNames when compared to str autoCompleteDB.prototype.getMatches=function(str,aList,maxSize) { /* debug */ //alert(maxSize+"ok getmatches"); var ctr=0; for(var i in this.aNames) { if(this.aNames[i].toLowerCase().indexOf(str.toLowerCase())==0) /*THIS LINE NEEDS TO BE CHANGED*/ { aList.push(this.aNames[i]); ctr++; } if(ctr==(maxSize-1)) /* counter to limit no of matches to maxSize */ break; } }; i have this part of code in JS: Code: var receiveReq = getXmlHttpRequestObject(); function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } } function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET","getChat_xml.php?chat=1&last=7", true); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(); } } function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); } } then in my getChat_xml.php i have: Code: $xml = '<?//xml version="1.0" ?><root>'; $last = 7; $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time" . " FROM message WHERE chat_id = " . db_input($_GET['chat']) . " AND message_id = " . $last; $message_query = db_query($sql); while($message_array = db_fetch_array($message_query)) { $xml .= '<message id="' . $message_array['message_id'] . '">'; $xml .= '<user>' . htmlspecialchars($message_array['user_name']) . '</user>'; $xml .= '<text>' . htmlspecialchars($message_array['message']) . '</text>'; $xml .= '<time>' . $message_array['post_time'] . '</time>'; $xml .= '</message>'; } $xml .= '</root>'; echo $xml; i get a "cannot cal a method getElementsByTagName of null" ??? i have no idea whats going on, help please? thanks I made some code to factor a quadratic equation and I could use some help finding situations where it finds the wrong answer. If you can find any problems, let me know. Thanks http://www.wdroom.com/factor.html Hi i need to find the highest average from all of the averages entered in this code, but i have to use an if statement only, no arrays. Could some one help please? Code: // ** Work out average ** // average= readingSum/totalReadings // ** Put average into a category and display everything ** // if(average<5) { catergory1=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Dry"); } else if(average>=5 && average<20) { catergory2=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Normal"); } else if(average>20) { catergory3=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Wet"); } // ** Find Highest average ** // Thanks. Hi, I have what I thought was a fairly simple problem that I would be able to solve on my own, but the code I have found is just too complicated for me to understand, so id appreciate any help. I think what i have is similar to the knapsack problem, but I have a really simple version of it. http://www.ms.unimelb.edu.au/~moshe/...psack.html#def Say I have a relatively small array of numbers: 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, 10. I just need to verify true or false if a combination of these numbers will add up to 21. The numbers will obviously be changing, ( and in array size), i guess i could just use if statements but it would be stupid and go on for ages. Could anyone point me in the direction of some simple code, or easy to understand way to go about this problem? Thanks Alright so for my website (I've totally revamped it and what not) I want to make a code highlighter for source code / tutorials I've posted. At the moment I'm just using some css: Code: div.code { font:1em "Courier New"; margin: 10px auto 10px auto; background-color: #FFFFFF; border: thick solid #555555; color: #000000; white-space: pre; font-size: 12; } So the code stays neat and in a box. But what I want to do now is somehow make a small javascript function that scans the text inside the html file etc : Code: <div class="code">float TimerTicksPerSecond = 0; float TimerTicksPerMillisecond = 0; int value = 0; std::string s = "hello world"; </div> and can format it so float and int is blue, "hello world" is red etc. Be a great help if someone can point me in the right direction. As from the javascript I've done myself I can't see it being to hard. I'm just unsure how to scan for text inside like I have above. Cheers Myth. I was hoping someone might be able to help me find an error in this script. I am pretty sure there is an error on line 9, but not sure. Any help is appreciated! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Days of the Week</title> </head> <script type="text/javascript"> <!-- HIDE FROM INCOMPATIBLE BROWSERS printdays(); // STOP HIDING FROM INCOMPATIBLE BROWSERS --> </script> </head> <body> <script type="text/javascript"> <!-- HIDE FROM INCOMPATIBLE BROWSERS function printDays() { daysOfWeek = new Array(7); daysOfWeek[0] = "Monday"; daysOfWeek[1] = "Tuesday"; daysOfWeek[2] = "Wednesday"; daysOfWeek[3] = "Thursday"; daysOfWeek(4) = "Friday"; daysOfWeek[5] = "Saturday"; daysOfWeek[6] = "Sunday"; var count = 0; do { document.write(daysOfWeek[count] + "<br />"); ++count; } while (count <= 6); } // STOP HIDING FROM INCOMPATIBLE BROWSERS --> </script> </body> </html> Hello, I've been trying the find the (x,y) co-ordinates of an element. I've been using; Code: document.getElementById(element).style.top document.getElementById(element).style.left However this doesn't always work in my script. Now, I've googled how to find the position of an element. And come accross many scripts which supposedly all find the position of any object. Some are very long scripts and some are very short all using a variety of methods. Incidently none of which work, they all return (0,0). I have a question, why would someone create a script to do what one line of code can do? Am I missing something. If I understand why it may help me work out why my script isn't working. Thank you. I'm having a hard time trying to get this script to work. I am trying to write a script that finds the highest of 5 numbers and places the highest number in the last textbox. Can anybody tell me what I am doing wrong? Code: <HTML> <HEAD> <TITLE>COMSC-100-1241 - Assignment #10 - Using "Greater Than" And "Less Than" Logic</TITLE> <SCRIPT TYPE="text/JavaScript"> function Go(code){ var number1 var number2 var number3 var number4 var number5 var highest var max number1 = parseFloat(document.getElementById("number1").value); number2 = parseFloat(document.getElementById("number2").value); number3 = parseFloat(document.getElementById("number3").value); number4 = parseFloat(document.getElementById("number4").value); number5 = parseFloat(document.getElementById("number5").value); max = parseFloat(document.getElementById("max").value); if (code == 0){ } if (max < number1){ max = number1 } if (max < number2){ max = number2 } if (max < number3){ max = number3 } if (max < number4){ max = number4 } if (max < number5){ max = number5 } document.getElementById("max").value = highest } </SCRIPT> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="500" ALIGN="center"> <TR> <TD> <DIV ALIGN="left"> <B>Instructions: </B> Answer the three questions and press "GO". Your score will appear. <BR> <BR> <B>Input Values: </B> <BR> <B>First Number:</B> <INPUT id="number1"> <BR> <B>Second Number:</B> <INPUT id="number2"> <BR> <B>Third Number:</B> <INPUT id="number3"> <BR> <B>Fourth Number:</B> <INPUT id="number4"> <BR> <B>Fifth Number:</B> <INPUT id="number5"> <BR> <INPUT TYPE="Submit" VALUE="GO!" onClick="Go(0);"> <BR><BR> <B>Output Values: </B> <BR> <B>Highest Number:</B> <INPUT id="highest"> </FORM> </DIV> </TD> </TR> </TABLE> </BODY> </HTML> Hi, I'm trying to select check boxes with particular values, unfortunately it is not a very well structured page at all which has left me clueless as to how to go about doing this, I'll show the page code and let you know what it is that I'm trying to do and hopefully somebody will be able to come up with a method of doing this! Full page code can be seen he http://pastebin.com/kBWqvXe3 Partial code: Code: // Partial code, full code at: http://pastebin.com/kBWqvXe3 <form action="itemtransfer.php" method="post"> <table width="760" height="399"> <tr> <td width="579" bgcolor="#000000" valign="top" style="border:2px inset;"> <table> <tr> <td align="center" valign="bottom"> <img border="0" width="43" height="43" src="http://sitename/images/items/item_allseeingeye.jpg" ONMOUSEOVER="itempopup(event,616210549)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="616210549"></center> </td> <td align="center" valign="bottom"> <img border="0" width="43" height="43" src="http://sitename/images/items/item_allseeingeye.jpg" ONMOUSEOVER="itempopup(event,616337548)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="616337548"></center> </td> <td align="center" valign="bottom"> <img border="0" width="43" height="43" src="http://sitename/images/items/item_allseeingeye.jpg" ONMOUSEOVER="itempopup(event,616023597)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="616023597"></center> </td> <td align="center" valign="bottom"> <img border="0" width="50" height="50" src="http://sitename/images/items/coes_animatedbook.gif" ONMOUSEOVER="itempopup(event,615394126)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="615394126"></center> </td> <td align="center" valign="bottom"> <img border="0" width="49" height="50" src="http://sitename/images/potion_yellow.gif" ONMOUSEOVER="itempopup(event,575558221)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="575558221"></center> </td> <td align="center" valign="bottom"> <img border="0" width="40" height="40" src="http://sitename/images/items/Aslan-Magic.jpg" ONMOUSEOVER="itempopup(event,615238517)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="615238517"></center> <td align="center" valign="bottom"> <img border="0" width="41" height="50" src="http://sitename/images/unique945.gif" ONMOUSEOVER="itempopup(event,616680604)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="616680604"></center> </td> <td align="center" valign="bottom"> <img border="0" width="43" height="43" src="http://sitename/images/items/item_zhulianpowershard.jpg" ONMOUSEOVER="itempopup(event,616672188)"; ONMOUSEOUT="kill()"><br/><center><input type="checkbox" name="checkbox[]" value="616672188"></center> </td> </tr> </table> </td> <td width="282" bordercolor="#000000" bgcolor="#666666" style="border:2px inset;" valign="top"><p>To send an item to another one of your characters, check the items off you would like to send on the left. Then, use the form below to tell us who you want the items to go to!</p> <p> <b>Items not included: </b><br /> <ul style="margin-top: -5px;"> <li>Equipped Items</li> <li>Player Bound Items</li> <li>Items in your vault</li> <li>Items on the tradeblock</li> </ul> </p> <p> <form action="itemtransfer.php" method="GET"> <input type="checkbox" name="includePlayerbound" value="1" onClick="javascript: document.location.href='http://sitename/itemtransfer.php?includePlayerbound=' + this.value;" /> <strong>Include Playerbound Items<br /><br />500 Points Per Godly Protection Set Item<br />200 Points Per Celestial Set Item<br />100 Points Per Oblivion Set Item<br />100 Points Per Sovereign Set Item<br />25 Points Per Other Playerbound Items</strong> </form> </p> <p><strong>Send to your character (lvl 10+):</strong><br/> <select name="self"> <option value="0">Select a Character</option> <option value="786786">B1LLY</option> </select> </p> <p> <input type="submit" name="submit" value="Send items!"> </p> </td> </tr> </table> </form> </td> </tr> </table> <p align="center"><font size="1"> <a href="/home.php">HOME</a> | <a href="/world.php">EXPLORE</a> | <a href="/treasury.php?type=55">TREASURY</a> | <a rel="nofollow" target="_New" href="http://wiki.***********">HELP</a> <!-- | <a href="/world.php?fbapp=1">SMALL SCREEN</a> --> </font><p align="center"> <font size="1"> <a href="/privacy.php">Privacy Policy</a> | </font><b> <!-- <font size="1"> <a href="/spampolicy.php">Anti-Spam Policy</a></font></b><font size="1"> | </font><b> <font size="1"> <a href="/antifraud.php">Anti-Fraud Policy</a></font></b><font size="1"> | </font><b> --> <font size="1"> <a href="/outwar_tos.php" rel="nofollow" target="_blank">Terms of Service</a></font> <br> srv 147 Page was generated in 3.044907 seconds</font></center> </div> </div> </center> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-16031817-1"); pageTracker._setDomainName(".***********"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html> What I'm trying to do is to check the boxes that are the 'item' named item_allseeingeye.jpg each image corresponds to a checkbox so I thought I could make an array to loop through all images and an array to loop through each of the checkboxes to get a matching index so I can check the checkbox. If anyone knows a better way of doing this I would really appreciate the help! Many thanks, David. I am making a website for a gravle company and they want a gravel yardage calculator. I have no idea how to use javascript at all, but I think that it can be used for this. I need to use it on an XHTML 1.0 Transitional page. If anyone can help me with this I would be very greatful. An example of what I need can be found at http://www.natraturf.com/calculator.cfm.
This is my first post on this website. It has a very clean design to it. I think I am going to enjoy myself here :P I am taking a class. And I am very sorry if this post does not belong here. It is a JavaScript class so, my guess was here. My professor has giving us three page sources from random sites. I can not figure this out though. This question has a page source from some random math test website. What we are to do with this page source is to figure out the ten correct answers to the question in the page source. No, not by doing the math, but figuring out where in the page source it is hiding. I can not find them for the life of me. I got the other two problems, but of course this is the hardest one Thank you for your help I put the page source in a notepad attach to this post. (My professor has removed parts of codes that included the name of the website he had gotten it off of. He also said the page source may need to be decoded.) I think I found what I am looking for. If you look where question one starts. Itll have <input type="hidden" name="corAns" value="27478035"> But, the answers are A, B, C, and D which would be 1, 2, 3, and 4 for D. So is <input type="hidden" name="numAns" value="4"> The correct line? I think that is to easier. He said this assignment was the hardest out of the three, and well, that was to easy? Hi all, I am in a non-major class called webprogramming working with javascript and I'm having an issue with a specific code wondering if someone could tell me what's wrong! So I am suppose to compute and return the average of all values in a given array named customerBalance, the array holds the amount of "what customers owe my business" (I dont own a business) and each item in the array holds the "customers balance", i also have to use a for() to process the array and calculate the average and divide by customerBalance length, and finally return the average. Here is my code so far <script> function average() { customerBalance for(i=0,i++) sum(customerBalance) total=sum/5 return average; }; </script> I know that this is COMPLETELY wrong, I am not sure on how i start typing the array, please don't be harsh I would really like to know how to do this. Thank you and have a great day hey guys im not new to javascript but arrays still confuse me exspecialy when put into loops ok say i had 2 arrays i have used jquerry to extract a question lets say this is the question How long is a piece of string? the answer is for this example infinite so what i want to do is search the question trough a array with 21984 and more in the future when it finds the match it then looks at the answers array at the same array length as where the question was found then sends the answer to a variable for later use could someone give me a example on how to do this please? I'm a bit of a Javascript noob, so please bear with me! I'm trying to create a piece of code that will check a webpage and replace any instances of a specific line of HTML with another line of HTML. The code I have so far doesn't work, but I have a feeling that's down to my awful Javascript skills! For example, in the following code I'd want to replace all instances of <li><a href="index.pdf">Index</a></li> with <li><a href="contents.pdf">Contents</a></li> Code: <div id="downloads"> <p>Please click on your downloads below:</p> <ul> <li><a href="index.pdf">Index</a></li> <li><a href="chapter1.pdf">Chapter 1</a></li> <li><a href="chapter2.pdf">Chapter 2</a></li> <li><a href="chapter3.pdf">Chapter 3</a></li> <li><a href="credits.pdf">Credits</a></li> </ul> </div> The Javascript I have so far is: Code: <script type="text/javascript"> var aEls = document.getElementsByTagName('a'); for (var i = 0, aEl; aEl = aEls[i]; i++) { aEl.href = aEl.href.replace('index.pdf','contents.pdf'); } Obviously this is meant to just replaces the a href elements, but I got a bit stuck after this! Any pointers would be much appriciated. |