JavaScript - A Little Advise On Javascript Garbage Collector, Please?
Hi guys,
Just a simple question, Since we can't delete object created with document.createElement(), and just let javascript internal garbage collection do the work. I would much appreciate if anybody would advise me, whether we should nullify the object first, for complete deletion by this collector? Thanks for reading, and advising... Hendra. Similar TutorialsHello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hi there I've just completed a lovely slideshow script on my homepage. It works great in Firefox, but doesn't display at all in IE. It's on a live test page he http://www.modern-wedding-ideas.co.uk/index2.html I'm sure I'm just missing something really simple. Any help would be greatly appreciated. Also, this is a copy and paste job: I'm a newbie to javascript! So please be gentle. Many thanks Nicola The student exam records is a record set with the name and score of the student. Get studentscore gets the score in a percent. It should look like. Gyazo - 1bca244a45819b54e0bb5b6ba6839aa6.png but it looks like Gyazo - 6e71a50d9d91c3d6bec5b965d0ebfa8e.png Code: // Store the student exam records in a variable. examRecords = openStudentExamRecords(); //// Variables / assignment. var examScore; var count = 0; count = Number(count); var grade; // Calculations. while (examRecords.readNextRecord()) { examScore = examRecords.getStudentScore(); examScore = Number(examScore); if (examScore == 90) { grade = "A" } //if (examScore >= 80 && examScore <= 89) { // grade == "B"; // count++; //} //if (examScore >= 70 && examScore <= 79) { // grade == "C"; // count++; //} //if (examScore >= 60 && examScore <= 69) { // grade == "D"; // count++; //} //if (examScore < 60) { // grade == "F"; // count++; //} document.writeln(examScore + grade + count); } } I have been given files for my site and would like to know what the following script does or could do ? Code: function parseScript(_source) { var source = _source; var scripts = new Array(); // Strip out tags while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) { var s = source.indexOf("<script"); var s_e = source.indexOf(">", s); var e = source.indexOf("</script", s); var e_e = source.indexOf(">", e); // Add to scripts array scripts.push(source.substring(s_e+1, e)); // Strip from source source = source.substring(0, s) + source.substring(e_e+1); } // Loop through every script collected and eval it for(var i=0; i<scripts.length; i++) { try { eval(scripts[i]); } catch(ex) { window.execScript(scripts[i]); } } return source; } this is one of the calls to this script I found in the other site files. Code: document.getElementById(element).innerHTML=parseScript(xmlhttp.responseText); is there a possible security risk on this ? any help on this is grately appreciated. Hi all, The following code is an assigment.I have it running with out any errors.It has to take the array (arrayToshuffle) and through running though the end of the (arrayToshuffle) the string has to be shuffled.We havent learnmt shuffle() yet.) I think the problem is these lines. arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; But no matter what varibles I put in these lines and how much i fiddle I carnt seem to get it to run without repeating the same elements in the output. I dont want anyone to fix it for me just advise on where I could look for problems. Am i missing somthing here? Heres the program if you run it you will see what I mean. <html> <head> <script> var arrayToShuffle = new Array('Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King'); var arraySize = arrayToShuffle.length; document.write('<h1>Array shuffling</h1>'); document.write('<p>Before shuffle: '+arrayToShuffle+'</p>'); SWAPS_TO_MAKE = 30; var index=0; var self_swaps=0; var counter = 0; while(counter < SWAPS_TO_MAKE) { var swapIndex = Math.floor(Math.random()*arraySize+1); arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; if(index =swapIndex) { self_swaps++; } counter++; index = (index+1 % arraySize); } document.write('<p>After shuffle: '+arrayToShuffle+'</p>'); document.write('<ul>'); document.write('<li>Swaps made: '+SWAPS_TO_MAKE+'</li>'); document.write('<li>Self swaps: '+self_swaps+'</li>'); document.write('<li>Effective swaps: '+(SWAPS_TO_MAKE-self_swaps)+'</li>'); document.write('<li>Effective rate: '+((SWAPS_TO_MAKE-self_swaps)/SWAPS_TO_MAKE)+'</li>'); document.write('</ul>'); </script> </head> <body> </body> </html> Thanks heaps Shayne Darcy Hi, I am having a slight difficulty and hope someone can easily set me straight. I am trying to use the following code to track a button click and the second onclick event, the urchin tracking is not being completed but the first function is.... can someone please hopefully set me straight easily on the code? Many thanks Steve123. Code: <input type="submit" name="Submit" value="Buy Product" class="buy" onClick="document.form.submit();javascript:urchinTracker('/html/productdeals_button.asp')"> Hi all, I have just stated university a few weeks ago and have never programmed before.I am really stuck on this assigment .In the programm you have to enter you date of birth throught prompt (22).then your year of birth (yyyy),then your month (nov). I am really stuck and have been for days in requards how to put the information gained through prompt function into a date object().So i can get the users day of birth .Heres the code i have written .the varibles num5+num9+num1 is the users input but i just dont know how to assign it to the date object I have tryed heaps of ways but carnt get any thing to work .Please Help. head> <script> var tit1=('<title> Get your Stats </title>'); var tit2=('<h1> IT\'s about time...</h1><br /> ') var num1 =(''); num1=prompt('Enter The Year You Were Born','19XX'); var currentTime = new Date() var year = currentTime.getFullYear() var ansVar = year-num1; //User input year calculation var ageEx = (ansVar/62.7)*100; // Life% calculation var num2=ansVar var num3= ansVar*365.2424; // Days calcuation var month =('janfebmaraprmayjunjulaugsepoctnovdec'); var num5 =(''); num5=prompt('Enter The Month You Where Born','jan'); num5=(num5.substring(0,3)); var lowCas=(num5.toLowerCase());//users input conmverted to lower case/ var num9=prompt ('Enter you date of birth','29'); var d = new Date (num5+num9+num1)//<<<<this random date entered here will give the day. alert (d); //STUCK HERE HOW DO I CONVERT num5+num9+num1 to a day????????:: document.write(tit1); //output document.write(tit2); document.write(('You have lived ')+ageEx.toFixed(0)+('% of your life.<br />')); document.write(('You are ')+ansVar+(' years old.<br />')); document.write (('You are ')+num3.toFixed(0)+(' days old.')); </script> </head> </html> Any advise would be appreciated thanks Shayne darcy. I have a page that takes nodes from drupal and pulls the athletes information and renders it into a roster page via a PHP array. initially the page did not have a logical sort and basically was rendered in the order of the node creation. I added sorttable.js to the file and you could then sort based on the header. However, our head coach wanted it to be sorted onLoad by player number (first column) so I added datatable and set aasorting to 0, asc and it actually sorts the second column (name) instead of column 1. No matter which column I set it to it only sorts the name column. If I could get some advice about how to fix this I would appreciate it. Code: <style type="text/css">table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { content: " \25B4\25BE" } </style> <script src="/jscript/sorttable.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#roster').dataTable( { "aaSorting": [[ 0, "asc" ]] } ); } );</script> <table width="100%" cellpadding="2" cellspacing="2" border="1" class="sortable" id="roster" style="border-bottom:1"> <thead> <tr> <?php if( ! empty($vars['sport']->field_sport_show_number) && 1 == $vars['sport']->field_sport_show_number['und'][0]['value'] ): ?> <th class="style4, sortBy" style="width: 14px;" data-sortType="numeric" id="number"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">#</span></th> <?php endif; ?> <th class="style4" style="width: 14px;" ><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Name</span></th> <?php if( ! empty($vars['sport']->field_show_class) && 1 == $vars['sport']->field_show_class['und'][0]['value'] ): ?> <th class="style4" style="width: 14px;"><span style="font-family: Arial, Helvetic 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 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 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? 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 written javascript for mouseover and click event to change the images. Here is a URL http://leowareit.com/imageselect/ The aim is when user click any of image, it should be selected and other should not be selected. I achieve this by changing the images. with following code Code: $(function() { $('.gender').click(function(){ $('.gender').each(function() { $(this).attr('src','http://dev.trivian.com/theme/trivianV2/icon/' + $(this).attr('alt')+'_up.png'); }); var src = 'http://dev.trivian.com/theme/trivianV2/icon/' + $(this).attr('alt')+'_down.png'; $(this).attr('src',src); }); }); And also when user do mouse over to the images, the images get changed with following code Code: $(function(){ $('.gender').hover(function(){ $(this).attr('src','http://dev.trivian.com/theme/trivianV2/icon/' + $(this).attr('alt')+'_down.png'); }, function(){ $(this).attr('src','http://dev.trivian.com/theme/trivianV2/icon/' + $(this).attr('alt')+'_up.png'); }); }); Now the problem is if I remove the mouse-hover code, the image selection is working properly with onclick, but with mouseover code, the click event get overwritten. Any help will be appreciated. I am not that good at javascript. Thanks |