JavaScript - What Happens In Javascript When You Do Not Catch A Thrown Exception?
What happens in Javascript when you do not catch a thrown exception?
Does the script get terminated prematurely? Similar TutorialsIf you try some codes and then catch exception, it should catch the exception when there is. However, if there is a setInterval method in the try clause, then the exception cannot be caught... why??? the following works ( a usual method is invoked in the try clause): Code: <script language="javascript" type="text/javascript"> function invoke() { var i=0; return i.x.y; } try { alert(invoke()); } catch(ex){ alert(ex); } //Any Exception will be caught. </script> if the highlighted line is changed as below (using setInterval method), then it fails... Code: <script language="javascript" type="text/javascript"> function invoke() { var i=0; return i.x.y; } try { setInterval(alert('invoke())',1000); } catch(ex){ alert(ex); } //The Exception will NOT be caught. </script> any idea? thx in advance For some reason i cant get this bit of code to work. You can ignore the php and html if its getting in your way. Thanks: Code: <div id="pl"> <? if($edit == true){ ?> <script type="text/javascript"> $("#add_playlist_form").css({display:"none"}); $("#add_playlist").click(function(){ alert($("#add_playlist").html()); if($("#add_playlist").html() == "Add a Playlist >>"){ $("#add_playlist").html("Hide <<"); $("#add_playlist_form").css({display:"block"}); } else{ $("#add_playlist").html("Add a Playlist >>"); $("#add_playlist_form").css({display:"none"}); } }); </script> <a href="#" id="add_playlist">Add a Playlist >></a> <form id="add_playlist_form" method="POST" action=" "> <input type="text" name="pl_name" class="add_playlist"/> <textarea name="pl_dsec" maxlength="200"></textarea> <input type="submit" name="submit_playlist" value="Add Playlist" class="submit_playlist"/> </form> <? } ?> <ul class="vList"> Hey folks. I am needing some help with an error I'm getting from a project I'm working on. First off let me preface this all with the fact that I'm a total javascript noob. I'm really trying to understand what I'm doing wrong. So any help or advice is MORE than welcome. Here's what is happening. I found this code that will duplicate a row in a table and modifiy the name of a input in the row. Well for my purposes I have two different tables I need to work with. (each one idividually) So I changed the code a bit to make it accecpt a variable to use for the table name. (before it was static) and now I'm getting a error. Code: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER)" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: http://www.tourandtravelnow.com/admin/scripts/faxPageScript.js :: addRow :: line 14" data: no] This is the old code that would work (only for one of the tables) Code: var clone; function cloneRow(){ var rows=document.getElementById('mytab').getElementsByTagName('tr'); var index=rows.length; clone=rows[index-1].cloneNode(true); var inputs=clone.getElementsByTagName('input'), inp, i=0 ; while(inp=inputs[i++]){ inp.name=inp.name.replace(/\d/g,'')+(index+1); } } function addRow(){ var tbo=document.getElementById('mytab').getElementsByTagName('tbody')[0]; tbo.appendChild(clone); cloneRow(); } onload=cloneRow; and here is my code that doesn't work. Code: var clone; function cloneRow(mytab){ var rows=document.getElementById(mytab).getElementsByTagName('tr'); var index=rows.length; clone=rows[index-1].cloneNode(true); var inputs=clone.getElementsByTagName('input'), inp, i=0 ; while(inp=inputs[i++]){ inp.name=inp.name.replace(/\d/g,'')+(index+1); } } function addRow(mytab){ alert(mytab); var tbo=document.getElementById(mytab).getElementsByTagName('tbody')[0]; tbo.appendChild(clone); cloneRow(mytab); } onload=cloneRow(mytab); So like I said any help would AWESOME! have a great day. Kevin. Double post I'm sorry. Please look at my other one.
Hi all, I have a question about following code. It is tested as working well but the problem is that I need to catch values of array registos from javascript function getData(dataSource, sql_str) in PHP and not only update values of each form element. Can you help me, plz? Code: <script language = "javascript"> function getData(dataSource, sql_str){ if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var registos = eval('('+xmlhttp.responseText+')'); document.getElementById("id_1").value=registos["cliente"]; document.getElementById("id_2").value=registos["designacao"]; } } xmlhttp.open("GET", dataSource+"&sql_str="+sql_str,true); xmlhttp.send(); } </script> <?php $sql_str="SELECT cliente, designacao WHERE cliente = '$cliente'"; $record=$db->sql_query($sql_str); list($registos[cliente], $registos[designacao]) = $db->sql_fetchrow($record); echo "<form id=\"form\">"; echo "<input type=\"text\" id=\"id_1\" name=\"registos[cliente]\" value=\"".$registos[cliente])."\">"; echo "<br>"; echo "<input type=\"text\" id=\"id_2\" name=\"registos[designacao]\" value=\"".$registos[designacao]."\">"; echo "<br>"; echo "<input type=\"button\" value=\"CONFIRMAR\" onclick=\"getData('mysql_query.php', '".base64_encode(serialize($sql_str))."')\">"; echo "</form>"; Ok I have a script that uses some global arrays and a function that looks like this: function functName(p) The other params are optional so they are accessed using: functName.arguments[1] etc. My problem is an error that I can't seem to catch even though it's an easy one. array = (functName.arguments[1] != undefined && evel('window.' +functName.arguments[1]) != undefined) ? do this: or this; The second param is an arrayName. It can be sent to the function as a string or a reference ( string: 'arrayName' , ref: arrayName) both operate correctly unless the array doesn't exist. Entered as a string, if the array doesn't exist it defaults to another array as required. However, if posted as a reference and it doesn't exist it throws an error: 'arrayName' is undefined Should I just use a 'try catch' method or it just something simple I missed? Hi I'm an AS3 dev learning Javascript. I'm currently writing a simple script that loads an image as seen below. I deliberately misspell the file name to test the fail. Code: var fileName = "anImageThatDoesntExist.jpg"; var image = new Image(); image.onload = imageLoaded; try { image.src = "images/" + fileName; } catch( error ) { console.log('load error', error.message ); } finally { console.log('unable to catch error!') } function imageLoaded( event ) { console.log('image loaded'); } When I run this script I was expecting the 'catch' to pick up the error and tell me that the file doesn't exist. The 'catch' statement is ignored and 'finally' is executed. I would be very grateful if someone could let me know if I'm writing the try/catch incorrectly or whether it doesn't work in this way when loading an image. Many thanks in advance.... I've got a function that returns the value of a radio button group. However the application allows to "hide" some groups on others responses and that effectively make the radio groups not exist. This causes issues with calculations using the total value of the groups combined. I need a way to return a value of '0.00' IF the function does not find the group/returns an error.This is what I currently got to but doesnt work. The function does not work at all. Code: function funcRadioCalc(RadioName) { var chkList1= document.getElementById (RadioName); var arrayOfCheckBoxes= chkList1.getElementsByTagName("input"); var bob; try { for( var i=0;i<arrayOfCheckBoxes.length;i++){ if (arrayOfCheckBoxes[i].checked) { bob= arrayOfCheckBoxes[i].value; if (bob!=undefined||bob!=""){ throw "yep"; }else{ throw "nope"; } } } catch (er){ if(er=="nope") { return "0.00"; } if(er=="yep") { return bob; } } } I would like to create a link from one page to another. Easy - I know. But I would like that link to to take me to a certain part of the other page, specifically towards the bottom of the page. Is that possible to do? And if so, what are the different ways I can specify where in the page to go? (i.e. what are the parameters that I can play with) Thanks! I am opening a blank window and writing a javascript on the new window to submit a form. when I execute a line "newWindow.document.write(newwdtxt2);\n\"(3rd line from last) I get an exception and last two lines do not execute. I see this problem only in IE 6, Code works fine with IE 7.Below mention is my code function openWindow(url,name,options) { var aToken = ""; aToken ="2121225434349231132674638921:something"; if(aToken=="") { aToken=document.formEMS.AUTHTOKEN.value; } var newWindow = window.open("", name); if (!newWindow) return false; var newwdtxt = ""; newwdtxt += "<html><head></head>\n"; newwdtxt += "<body>\n"; newwdtxt += "<form name=\"eventForm\" method=\"post\" action="+url+ ">\n"; newwdtxt += "<input type=\"hidden\" name=\"AUTHTOKEN\""; newwdtxt += "value= '";newwdtxt += aToken+"'/>\n"; newwdtxt += "</form>\n"; newwdtxt += "<scr"; var newwdtxt1 = ""; newwdtxt1 += "ipt type=\"text/javascript\" language=\"javascript\">\n"; newwdtxt1 += "window.onLoad=document.eventForm.submit();\n"; newwdtxt1 += "</scr"; var newwdtxt2 = ""; newwdtxt2 += "ipt>\n"; newwdtxt2 += "</body></html>\n"; newWindow.document.write(newwdtxt); alert(newwdtxt); newWindow.document.write(newwdtxt1); alert(newwdtxt1); alert(newwdtxt2); newWindow.document.write(newwdtxt2); alert('wrote newwdtxt2'); return newWindow; } Please help me to figure out what is the problem? Hello: I have a Fire Fox 3.5.2 error console message regarding a DHTML script: Error: uncaught exception: [Exceptions: ... "Not enough arguments" nsresult "0x8057001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" Location: "JS frame :: (file path) upHandler :: line 102" no data] The line referenced is: document.removeEventListener('mouseup', upHandler); It is part of a drag function that is applied to a container div. I have successfull used this code block, copied from Orielly's Javascript: The Definitive Guide, 4th Edition in another project. The only real difference is that the code in the working use is div tags hard coded. In the one giving me problems, the div tags are written using document.write() in a function that is called in the body of the document when the page loads. I could supply the code context, but it is several hundred lines. The project is not available at present on the web to surf to but the one project that works is jekillen.com/jekillen/content/web_design/OOP_panel/test_OOP_DEV_ALT.php The code in question is 'beginDrag'. There is a panel called fortune cookie which the user can drag, and a panel called 'Advisory' that the user can also drag around after clicking button labeled 'message'. Any info, suggestions, advice? Thanks in advance. Jeff K uncaught exception: Syntax error, unrecognized expression:
Code: :([rel*=qnt_Rc]) I have this code: Code: grpDiv = $$('div:([rel*=' + txt_val + '])'); Which when operaterated on, we have: Code: grpDiv = $$('div:([rel*=qnt_Rc]) This error: uncaught exception: Syntax error, unrecognized expression: Code: :([rel*=qnt_Rc]) Is new. The code in question has been around for about a year and no issues with prototype 1.6.1. Yet we upgraded to 1.7, and this error started showing. any ideas what this could be and how to fix it? thanks I can't get any info from Firebug except that one line, uncaught exception [object Object]. The code fully worked, then I needed to make it dynamically create Sortables from the scriptaculous library based on how many X were in a table in my database, which I've done, and I'm thinking it may be a simple slight parse error of some type, I'm not too good with Javascript, because now my script barely works. I've double checked the script's source code, the PHP variables are exactly what they should be. Code: print<<<HERE Sortable.create('sortlist$box', { tag: 'img', overlap:'horizontal',constraint:false, containment: $list, dropOnEmpty: true, onChange: function(item) { var list = Sortable.options(item).element; if(changeEffect) changeEffect.cancel(); changeEffect = new Effect.Highlight('changeNotification', {restoreColor:"transparent" }); }, onDrop: function(item) { var thing=Sortable.options(item).element.identify(); var anchors = document.getElementById(thing).childNodes.length-2; if(anchors > 20){ alert('This box had 20 creatures in it already, your last action has not been saved.'); window.location.reload(); } else{ new Ajax.Request("saveImageOrder.php", { method: "post", parameters: { data: Sortable.serialize("sortlist$box") } }); } } }); HERE; $box++; } ?> }); </script> if you solve this I'll send ya $10 via paypal 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. 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 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 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 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?. 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? 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 |