JavaScript - Why Error Console Tells Me :exp Is Null?
Hello,
Error Console tells me : exp is null Line 10 This does not make any sense to me. Could someone look at the short script below and tell me why I get this message? I know how to make this script work, but I just want to understand why function changePar cannot access the variable exp in the script below. Thank you very much. <code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Exercise 2</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <script type="text/javascript"> exp=document.getElementById("experiment"); function changePar() { exp.getElementsByTagName("button")[0].onclick=function() { document.getElementById("changingParagraph").innerHTML="Hello World"; } } window.onload=changePar; </script> </head> <body> <div id="experiment"> <button>Click Here</button> </div> <p id="changingParagraph"></p> </body> </html> </code> Similar TutorialsI would like to have a button just like for firebug, for error console, and that it would open error console window like for firebug. Is there a setting for that in FF, or some kind of addin outthere ?
What can I do to find out what the errors in the error console mean?
Hi I am having trouble with a script. I cannot figure out why I get the message: error: null is null or not an object (In IE8) The site is: www.rayburns.com I have check the javascript for the navigation bar and for the rotating images and cannot see what is missing. Not sure what is not being called. Can someone please help with this. Thank you in advance! Strange problem here... I'm implementing google's JS tracking code verbatim which determines whether or not the current site is using HTTP or HTTPS. It builds a dynamic URL used as the "SRC" parameter in the SCRIPT statement. On browsers I'm testing with(FF, IE, Chrome) there's no problem running the code. However, there are some people in the office who get an FF or IE error (same versions as mine) on the URL as the SRC parameter. The error, in the FF Error Console, is this: Quote: illegal character http://www.google-analytics.com/ga.js ? ? ? ? --> question marks appear in console I can't figure it out since I can't create this error on any of my browsers. Could this be related to something like browser security settings or add-ons? Hello, I'm working on some php and javascript. I have php creating some forms using values from a database and wrapping them in divs called showform1, showform 2 etc I then want to use Javascript to show one form at a time when I click on a tickbox. So I've got it working so when you click on a checkbox and it shows the right form, but I want it to hide all the others first so it only shows one at a time if possible. When I do this is errors saying document.getElementById(showform1) is null - it does this for all the forms not just the first one. My php goes like this: PHP Code: $i=1; //loop through all things in db while ($info_query = mysql_fetch_assoc($info)) { ?> <label>Item <?php echo $i;?></label> <input type="radio" name="show" value="show" onclick="showhide(this.value,'showform<?php echo $i;?>')"/> //here's the div with the dynamically generated ID... <div id="showform<?php echo $i;?>" style="visibility:hidden;height:0px;"> <p> info for item 1 </p> </div> //increment the counter so the next div has a different name $i=$i+1; } My Javascript looks like this: Code: <script type="text/javascript"> function showhide(radval,divid) { if(radval=="show") { <?php //hide them all first $i=1; while ($details_query = mysql_fetch_assoc($details)) {?> var showform<?php echo $i;?>; document.getElementById(showform<?php echo $i;?>).style.visibility="hidden"; document.getElementById(showform<?php echo $i;?>).style.height="0px"; <?php $i=$i+1; } //then show just the one ticked ?> document.getElementById(divid).style.visibility="visible"; document.getElementById(divid).style.height="auto" } } </script> the details and info queries are the same query...each looping through the same data. It works if I don't hide all the values first, and shows each form when I tick the box, but if I try to hide them all and THEN make one visible, the first line that hides the divs always errors. I've moved the JS around to the footer, the header in case its because stuff hasn't loaded yet, but it doesn't make sense as it has loaded to work to show the div. Really appreciate your help. Thanks, Nicola Hi, I am getting an error on this code - sometimes! - and I'm not sure what it is. If I run this as is there is no error. If I add it into another page with other stuff it's ok for a while and then I get an error. So, I added my new page block my block to this code and waited for the error to appear so I could determine a conflict - but it was fine. And then a few clicks later the error. This is the error in IE. In Firefox it seems to be fine lol. Line 159 Char 3 'window.document.sendform.message_text' is null or not an object Can someone make any suggestions? Code: <script language="JavaScript" type="text/javascript"> maxlen = 160; countLen(); function countLen() { message_text = window.document.sendform.message_text.value; realLength = message_text.length; if (realLength>maxlen) { realLength = maxlen; window.document.sendform.message_text.value = message_text.substring(0,maxlen); } message_text = window.document.sendform.message_text.value; // del enter var m = message_text.match(/[\r\n]/); if (m !== null) { window.document.sendform.message_text.value = message_text.replace(/[\n\r]/g, '') } window.document.sendform.messlen.value=maxlen-realLength; } </script> <cfset thismessage = "Hi, is this a start"> <cfform action="step2.cfm" method="post" id="sendform" name="sendform"> <cfoutput><textarea id="styled" name="message_text" onkeypress=countLen() onkeydown=countLen() onkeyup=countLen() onchange=countLen() onmouseover=countLen() rows="4">#thismessage#</textarea></cfoutput> <table width="331" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="5"></td> <td width="26"><cfoutput> <input name="messlen" type="text" value="160" class="counterField" onFocus="this.form.message_text.focus();" /></cfoutput></td> <td width="300">characters remaining</td> </tr> </table> </cfform> Thanks! Much appreciated! Kind regards, jo Hi I am using a custom form elements script in the link below: www_bristolstreet_co_uk/page/find_a_dealer.htm and an error for null object is appearing from this line: active = option[0].childNodes[0].nodeValue; Can anyone please help? I am a novice at Javascript but got this script working perfectly on my local machine - once I loaded it the live site it didn't work... any advice would be greatly appreciated. I have a bug that is only seeming to effect IE 8:. It seems to have a problem with this line: theSelectBox.selectedIndex = -1; This is where my full page is: http://www.mauirealestate.net/advancedsearch-rets.php Also has a weird display issue in IE8, but not in "compatibility view", which the bug may fix. Works and looks beautiful is Safari and Firefox. Any suggestions are helpful. Hi, I have added an validation script for Pizza menu. Validation working fine in all browsers except IE. When I working in IE8 it throws an error "length is null or not an object error in IE8". Please help me. See Java script code below: <script> function UnCheckRadios(radioButtonGroupName) { var formName = "frmOrder"; var form = document.forms[formName]; alert(form); var noOfRadioButtons=form[radioButtonGroupName].length; for(var x=0;x<noOfRadioButtons;x++) { chk=form[radioButtonGroupName] .checked=false; } } </script> PHP code: <input type="radio" id="<?=$subitem['subgroup_id'];?>_comboleft" name="<?=$subitem['subgroup_id'];?>_comboleft" value="<?=$subitem['id'];?>:Left Side" onclick="UnCheckRadios('<?=$subitem["subgroup_id"];?>_combowhole');"> Hello I am using a timer which goes down from 2 minutes to zero when 'jsp' is called. Timer is written in javascript. I am getting an error that document.form1.timerMin.value=<%=min%> is null or not an object. Here is the code (t.jsp): <% /* Default timer */ int min = 2; int sec = 5; /* Check for timer params */ try { String timerMin = request.getParameter("timerMin"); if (timerMin==null)timerMin=""; if (timerMin != null) { min = Integer.parseInt(timerMin); } String timerSec = request.getParameter("timerSec"); if (timerSec==null)timerSec=""; if (timerSec != null) { sec = Integer.parseInt(timerSec); } } catch(Exception m) { System.out.println("generated exception..............:"+m); } %> <script language="JavaScript" type="text/javascript"> <!-- /* Initialise timer */ var min = <%=min%>; // set the minutes var sec = <%=sec%>; // set the seconds function countDown() { sec--; if (sec == -1) { sec = 59; min--; } /* Write timer state to hidden form fields */ document.form1.timerMin.value=<%=min%> document.form1.timerSec.value=<%=sec%>; time = (min<=9 ? "0" + min : min) + " min and " + (sec<=9 ? "0" + sec : sec) + " sec "; document.getElementById('theTime').innerHTML = time; SD=window.setTimeout("countDown()", 1000); if (min == 0 && sec == 0) { window.clearTimeout(SD); } } window.onload = countDown(); --> </script> <style type="text/css"> <!-- .timeClass { font-family:arial,verdana,helvetica,sans-serif; font-weight:normal; font-size:10pt; } --> </style> <table width="100%"> <tr><td width="100%" align="right"> <span id="theTime" class="timeClass"></span> </td></tr> <form method="post" name="form1" id="form1" action="t.jsp" <td width="50%" valign="middle"> <input type="hidden" name="timerMin" value="<%=min%>"> <input type="hidden" name="timerSec" value="<%=sec%>"> <div align="center"><a href="javascript:form1.submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','/lms/images/submit_0.gif',1)"><img name="Image3" border="0" src="/lms/images/submit_0.gif" width="70" height="30"></a></div> </td> </form> Looking forward for an early reply. Thanks İ want to use this code but when the page opens, I get a null reference error. When I open the page a second time, this error doesn't occur. I understand when the site caches, this error doesn't occur. The error comes from tb_show function. My code: <script type="text/javascript"> function writeCookie(CookieAdi) { var dtGun = 1 var strValue = "1" if (dtGun == null || dtGun == "") dtGun = 365; var d = new Date(); d.setTime(d.getTime() + (dtGun * 24 * 60 * 60 * 1000)); var zt = "; expires=" + d.toGMTString(); document.cookie = CookieAdi + "=" + strValue + zt + "; path=/"; } function readCookie(cookieadi) { var c = document.cookie; if (c.indexOf(cookieadi) != -1) { s1 = c.indexOf("=", c.indexOf(cookieadi)) + 1; s2 = c.indexOf(";", s1); if (s2 == -1) s2 = c.length; strValue = c.substring(s1, s2); return strValue; } } writeCookie('OnerFacebook'); if (readCookie('OnerFacebook') != 1) { tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&TB_iframe=true&height=500&width=300&modal=true', ''); } </script> What should I do for it? Hello, I hope you can help me, I have used a really simple image script which features 3 thumbnails, you click one thumbnail and it loads the image as a larger image. Works perfectly in Google Chrome, Firefox - and then I've come to try in IE8... works perfect BUT javascript error as follows: - Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; InfoPath.2; .NET4.0C) Timestamp: Fri, 31 Dec 2010 17:14:48 UTC Message: 'document.images.image0' is null or not an object Line: 13 Char: 1 Code: 0 Here is the code, what am I doing wrong? I can't spot it, theres a couple of threads online from 2005 about this script but none have helped me clear the error. Code: <html> <head> <script language="JavaScript"> image0 =new Image(); image1 =new Image(); image2 =new Image(); image0.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" image1.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" image2.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" document.images['image0'].src=image0.src; document.images['image1'].src=image1.src; document.images['image2'].src=image2.src; function image_click(clicks) { if(clicks==0){document.images['large'].src=image0.src;} if(clicks==1){document.images['large'].src=image1.src;} if(clicks==2){document.images['large'].src=image2.src;} } </script> </head> <body> <a href="javascript:image_click(0)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" height="93" width="123" alt="" name="image0" border="0"/></a> <a href="javascript:image_click(1)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" width="123" alt="" name="image1" border="0"/></a> <a href="javascript:image_click(2)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" height="93" width="123" alt="" name="image2" border="0"/></a> <img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" align="middle" border="0" width="418" height="284" name="large"> </body> </html> Hey Guys, I wondered if anyone would be kind enough to look at an issue I am having running a Javascript on IE. The script works fine in FF and Chrome but chucks up an error in all versions of IE so the Menubar does not display child pages. Here's the Error: User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Tue, 16 Aug 2011 14:45:53 UTC Message: 'lastChild' is null or not an object Line: 31 Char: 3 Code: 0 The full script is he http://www.makingtrails.com/wp-conte...ks3/js/menu.js Any help much appreciated as the author of this script is not providing any support. Thanks Jon Hi, first post here. I was working on code for opening a link in a new window when clicked. I read somewhere that it's a good idea to remove all of the javascript elements from the HTML. So I pieced it together and it works. But I get the following error in IE8: Code: Message: 'document.getElementById(...)' is null or not an object Here's the relevant HTML: Code: <a href="http://www.samplesite.com" id="sampleid">Sample Text</a> And here's the relevant javascript that I put in a seperate .js file: Code: function samplefct() { window.open(this.href);return false; } window.onload = function() {document.getElementById("sampleid").onclick = samplefct; } The code does work as planned. But I'd still like to get rid of the error. Can anybody think of a different way of stating the javascript that would perform the same thing and lose the error? Any help would be greatly appreciated. Thanks! IB Hi , I have a an application which works fine on XP IE6, but the same application throws error " Java Script Error Style is null or not an object" on XP IE8 and Windows 7 . Please help me to resolve this issue. Please Tahnks in advance I'm working with greasymonkey scripts. Firefox JS console would always display GM script errors, but all of the sudden it stopped doing that. Script just won't load and no errors are displayed. I didn't touch any settings, yesterday they were showing fine, today none are displayed. Would appreciate any help.
Hi, i'm having problems with my console game, when i type in help when testing it just doesn't do anything, it's probarly a stupid mistake but i can't find what i did wrong :s index.html code Code: <html> <head> <script type="text/javascript" src="scripts/jquery.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Console Game Project</title> </head> <body> <div id="console"> <p id="message_startgame">Welcome to Nieli's game! To control the game you must type in commands</p> <p id="area_northcorridor">You are in the north door. There is a sword on the ground.</p> <p id="message_help" style="display: none;">Here is a list of commands</p> <!-- PLACEHOLDER: THIS IS WHERE EVERYTHING WILL BE INSERTED BEFORE --> <div id="placeholder"></div> <form onsubmit="return false;"> <input type="text" size="50" autofocus="autofocus" id="command_line" /> </form> </div> <script type="text/javascript" src="scripts/game.js"></script> </body> </html> game.js code Code: //been to variables beentonorthdoor = true; // //Item variable sword = false; // //Current room currentroom = "n_corridor"; // $(document).ready(function() { $("form").submit(function() { var input = $("#command_line").val(); if (input == "help") { $("#message_help").clone().insertBefore("#placeholder").fadeIn(1000); } $("#command_line").val(""); }}; }}; I have on my website ( www.nieeli.com/game/ ) the index.html, then a folder scripts with jquery.js and game.js in.. Could anyone help me Oh, just noticed there is a Jquery help section... Sorry I use console.log to print the dom element info, but some results make me very confused.The code is below, you can paste it to a file and browse it. //********************** <html> <head> </head> <body> <script type="text/javascript"> function showObjInPage(obj) { document.write("=======================================<br/>"); document.write((typeof obj) + "<br/>"); document.write("length: " + obj.length + "<br/>"); ///!!! 0, may ok document.write(obj); //!!!!!write nothing for (var prop in obj) { document.write(prop + " = " + obj[prop] + "<br/>"); } document.write("=======================================<br/>"); } function consoleLog(obj) { console.log("=======================================<br/>"); console.log((typeof obj) + "<br/>"); console.log("length: " + obj.length + "<br/>"); //!!!!! this is the confuse, it is 0, but the code below show obj correct! console.log(obj); //!!! write all the p elements for (var prop in obj) { console.log(prop + " = " + obj[prop] + "<br/>"); } console.log("=======================================<br/>"); } var elems = document.getElementsByTagName('p'); //console.log(elems); //console.log(elems.length); showObjInPage(elems); consoleLog(elems); </script> <p>p1</p> <p>p2</p> <p>p3</p> <p>p4</p> </body> </html> I want to print the p elements info use console.log, it is ok to log the elems, but the elems's length is 0, so it is not consistent! Maybe my code need to write after the 'p' element, but the problem is very confused. Is it a chrome console.log bug or just I do something wrong? i'm working with a javascript on a drupal website, but the saving function seems to work only as soon as i click 2 times on the "save" button. the code that fires the function is: Code: var param ="&usuario="+usuario+"&nivel="+nivel+gano+porc_gano+gasto+porc_gasto+tengo+porc_tengo+debo+ porc_debo+plazo_debo; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = server_direction +"setMisDatos?callback=respuestaGuardarMisDatos¶m="+encodeURIComponent(param); var h = document.getElementsByTagName("script")[0]; h.parentNode.insertBefore(s, h); //or h.appendChild(s); the chrome console tells me the error is in the last line i copied, but i don't undertand what kind of error it is. using chrome console (specifically the "network" one), i see that it's written in red, status/text "failed", type "undefined" size/content "13 B / 0 B"; when it works it's: status/text "200/OK", type "text/json", size/content "256 B/ 38B". i'm not an expert with this, is there some more information that could be useful? the code fires a netbeans function, that stores data to a postgresql database, so i have like 100 variables that has to be stored when i click on the "save button". Actually before i put parentNode.insertBefore, there used to be appendChild(s), but then i found out this algorithm from google analytics, which seems to be working better than the previous one. Having said that, i can tell you that the GET works after the first time i click perfectly, with some weird things happening, like if i browse another tab for a while, then go back to the page, and click on save, it won't work again (same error). The variables are written like this: Code: var plazo_debo_casa1 = (getValor("plazo_debo_casa1")); var plazo_debo_casa2 = (getValor("plazo_debo_casa2")); var plazo_debo_casa3 = (getValor("plazo_debo_casa3")); var plazo_debo_prestamo1 = (getValor("plazo_debo_prestamo1")); var plazo_debo_prestamo2 = (getValor("plazo_debo_prestamo2")); var plazo_debo_prestamo3 = (getValor("plazo_debo_prestamo3")); var plazo_debo ="&plazo_debo_casa1="+plazo_debo_casa1+"&plazo_debo_casa2="+plazo_debo_casa2+"&plazo_debo_casa3="+plazo_debo_casa3+"&plazo_debo_prestamo1="+plazo_debo_prestamo1+"&plazo_debo_prestamo2="+plazo_debo_prestamo2+"&plazo_debo_prestamo3="+plazo_debo_prestamo3; and then together in the "param" variable. Is it clearer now? i tried to copy document.head.appendChild(s); instead of parentNode.insertBefore(s,h), but it still behaves the same way. Still not any suggestions? This is part of the javascript file loading on my page, and since the function setMisDatos is in netbeans and it works correctly as soon as it's fired (at least, that's what i notice after the first click), i don't think it's worth copying part of it here, right? are there maybe too many variables for the GET method? is there a way to check GET errors? i'm sorry for not being an expert but i would really like some help here. |