JavaScript - Null Check Not Working
Hi All,
This code returns "result: unknown". A successful check for null should return "result: isNull". Suggestions? Code: var myValue = null; var myResult = "unknown"; if (myValue == null) { myResult == "isNull"; }; alert("value: " + myValue + "\nresult: " + myResult ); Similar TutorialsHi i have done some reading on the net today because i am getting an error on ie. I did find the javascript twice in my code, once in the header and once here, so i removed it from the header. I also changed to src to the full url. But i am still getting this and i dont know why. the file is located in the root directory. Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; msn OptimizedIE8;ENUS) Timestamp: Sat, 30 Jul 2011 16:03:05 UTC Message: 'null' is null or not an object Line: 8 Char: 3894 Code: 0 URI: http://www.mysite.com/swfobject.js Code: <script type='text/javascript' src='$CONST_LINK_ROOT/swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('player.swf','player','400','300','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv'); s1.write('preview'); </script> <embed src='$CONST_LINK_ROOT/flvplayer.swf?file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv&autoStart=false' width='175' height='175' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed> would appreciate any suggestions thanks. i was on 1.5 swfobject i did download 2.2 and im guessing all you do is replace the swfobject.js file to upgrade it, but what happened is it gives me this now. Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; msn OptimizedIE8;ENUS) Timestamp: Sat, 30 Jul 2011 16:31:08 UTC Message: 'SWFObject' is undefined Line: 1283 Char: 1 Code: 0 URI: http://www.mysite/video_admin.php?type=v i dont mind going back to the old version i just need to get this working and im soooooooo lost lol ok another update, this is becomming maddening lol. once i have this line in the header php Code: <script type='text/javascript' src='$CONST_LINK_ROOT/swfobject.js'></script> I never have to use it again as long as they header php is included correct? This is what is driving me nuts, im back on 1.5 and it says its undefined Code: but am in not defining it on this line? ---> var s1 = new SWFObject('player.swf','player','400','300','9'); <script type='text/javascript' src='swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('player.swf','player','400','300','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv'); s1.write('preview'); </script> Another Update. I am back to the original question. null is null or not an object.. in my search i have found this found a solution. basically Internet Explorer is crappy and doesnt like the setAttribute property so had to change the onchange handler by directly changing the attrbute for the object like so. object.onchange = function() {} i have no idea what they means, does that mean i need to change swfobject.js or does that mean i have to change my xml request. and if it is the swfobject i have no clue what they mean or what lines 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! Please help me with this code to determine whether the check box has been checked. I get "Thank you" even if I don't check the check box. <script type="text/javascript"> var uncheck = document.getElementById().checked == false; var accept; function checkAccept() { var uncheck; if (uncheck == false){ alert ("You must accept the terms."); } else (uncheck == true) { alert ("Thank you."); } } </script> <form> <br />Please accept the terms by clicking the box below: <br />Accept terms: <input type="checkbox" id="accept" value="Y" /> <br /><input type="button" name="btn" value="Accept" onclick="checkAccept()" /> </form> </body> </html> Hi Guys, This is my first post, apologies in advance. I'm new to javascript and working on a form, for some reason the checkboxes work fine in Google Chrome but ar enot working corectly when using IE. Can anyone put me out of my misery? I've attached the code below Thanks in advance Code: //The Javascript // Functional Code - NO NEED to Change function f40_Disable(f40_par,f40_obj,f40_state){ if (f40_par){f40_clds=f40_AllElements(document.getElementById(f40_par)); } else { f40_clds=f40_AllElements(f40_obj.parentNode); } if (!f40_obj.ary){ f40_obj.ary=new Array(); for (f40_0=0;f40_0<f40_clds.length;f40_0++){ if (f40_clds[f40_0].tagName=='INPUT'||f40_clds[f40_0].tagName=='SELECT'||f40_clds[f40_0].tagName=='TEXTAREA'){ f40_obj.ary[f40_obj.ary.length]=f40_clds[f40_0]; } } } for (f40_1=0;f40_1<f40_obj.ary.length;f40_1++){ f40_obj.ary[f40_1].removeAttribute('disabled'); } if (f40_obj.checked==f40_state){ for (f40_2=0;f40_2<f40_obj.ary.length;f40_2++){ f40_obj.ary[f40_2].setAttribute('disabled','disabled'); } } f40_obj.removeAttribute('disabled'); } function f40_AllElements(f40_){ if (f40_.all){ return f40_.all; } return f40_.getElementsByTagName('*'); } Code: <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[0]' value='BW' onclick="f40_Disable(null,this,false);">BW <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipFirst"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[1]' value='Advantage' onclick="f40_Disable(null,this,false);">Advantage <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipLast"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[2]' value='MS' onclick="f40_Disable(null,this,false);">MS <input type="text" size="15" disabled="disabled" name="ShipEmail"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[3]' value='MOC' onclick="f40_Disable(null,this,false);">MOC <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipCompany"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[4]' value='Lk' onclick="f40_Disable(null,this,false);">Lk <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipAddress1"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[5]' value='CM' onclick="f40_Disable(null,this,false);">CM <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipAddress2"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[6]' value='Ga' onclick="f40_Disable(null,this,false);">Ga <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipCity"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[7]' value='Ol' onclick="f40_Disable(null,this,false);">Ol <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipZip"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[8]' value='Iy' onclick="f40_Disable(null,this,false);">Iy <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipZip1"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[9]' value='TPA' onclick="f40_Disable(null,this,false);">TA <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipZip2"> <p><LABEL ACCESSKEY=''><input type='checkbox' name='apps' id='apps[10]' value='CT' onclick="f40_Disable(null,this,false);">CT <input type="text" size="15" maxlength="30" disabled="disabled" name="ShipZip3"> I havent included the whole script as it's quite long, I'm assuming the problem is somewhere within this section. Thanks. Hi I've implemented Busybox on a website to display FLV files in a popup player. This works fine, except for the following error in IE (FF is fine) when I close the popup: 'null' is null or not an object I think I've narrowed it down to the following block of code, but am stuck as to what to do from here. Code: var cl = new Element('img',{ 'styles':{ width:'24px', height:'24px', position:'absolute', top:'-20px', right:'-20px', 'z-index':'100000' }, 'src':'bumpbox/closed.png', 'id':'closer' }) cl.addEvent('click',function(e){ e = new Event(e).stop(); bg.dispose(); $(el).getChildren().dispose(); eff2.start({ 'width':[maxw,1], 'height':[maxh,1], 'left': [endleft,middleH], 'top': [endtop, middleV+s] }) }) The IE error is just giving me line number 1 of the php, but the error, I'm sure, lays in the Javascript. Many thanks On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed I know that unlike PHP, NULL in JavaScript must be quoted as a string. Does it matter if you use single or double quote?
I'm guessing this question will be one of the easiest questions ever posted but I'm just not getting this fix. I have a simple Javascript program that calculates a users pace for their run. The inputs are done through an HTML Form. The user can input hours, minutes, & seconds of their run. Then the distance number & measurment. Then finally the pace desired. I am having some trouble with null values in this program. If I input a 0 in hours and then fill everything out the program works great. 100%! But, if I leave the field blank and hit calculate I get a NaN. I'm guessing I need some kind of statement like if this value is null set it to zero but I am not having any luck with exactly what kind of syntax I need. So here is the code, again not very complex, any help would be greatly appreciated! function calculateTime(){ var time_hour = parseInt(document.getElementById("time_hour").value); var time_min = parseInt(document.getElementById("time_minute").value); var time_sec = parseFloat(document.getElementById("time_second").value); var dist_num = parseFloat(document.getElementById("dist_num").value); var pace_choice = document.getElementById("pace_choice").selectedIndex; var dist_choice = document.getElementById("dist_choice").selectedIndex; var total_sec = (time_hour * 3600) + (time_min * 60) + (time_sec); // Then I'm guessing my if statement would go here somewhere? Bonjour all. I am trying to activate a function once an iframe is closed. so i am trying to use: window.opener.pageUpdate(); which i get an error of Error: window.opener is undefined Source File: https://web111.secure-secure.co.uk/s...js/thickbox.js Line: 270 Which lead me to believe that my parent window has not got a name so i used window.name = "main"; in my parent and window.main.pageUpdate(); in the child and get same kind of error. Could someone please help me out! I need to check to see if a cookie has been previously created: Code: var startnum = readCookie('a1'); if (document.cookie.indexOf('a1') == -1){ var startnum = "0"; } Should line 2 be: Code: if (document.cookie.indexOf('a1') == null){ ? Does == -1 do the same thing? On my site I have a Javascript error in my FireBug console: Year is 'null' Code: document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); here is my site: http://harveys.blueplanetdns.com/harveys-shop/ For some reason i'm getting the error of "length is null". Which is from this . Code: function display_form(id) { //Create some variables var html = ""; var container = "form_container"; var menu = load_menu(id, false); //Get id for ( var i = 0; i < menu.length; i++ ) { alert(i); } http = getHTTPObject(); http.onreadystatechange = function() { if ( http.readyState == 4 && http.status == 200 ) { document.getElementById(container).innerHTML = http.responseText; } else { document.getElemenyById(container).innerHTML = "Loading..."; } } http.open( "GET", "includes/forms.php?form=" + id ); http.send(); //Watch input fields //login_listener(); }/* Here is the function: Code: function load_menu(menu, return_d) { //Availible menus var data = []; data [ 'login' ] = [ 'Login', 'Register', 'Recovery' ]; data [ 'settings' ] = [ 'Profile', 'Account', 'something' ]; if (return_d == false) { return data[ menu ]; } else { //Menu container ID's var cons = Array('menuitem1','menuitem2','menuitem3'); for ( var i = 0; i < cons.length; i++ ) { document.getElementById(cons[i]).innerHTML += data[ menu ] [ i ]; } } } Extra info: id = login menu = login New problem, taken from another website I posted this on: Error: Code: Error ``user_node[0].firstChild is null'' [x-] in file ``*url removed*'', line 63, character 0. As you can see it says that the value is NULL although it shouldn't be... Here is the JavaScript which the error refers to: Code: function manageMessage() { if( receiveReq.readyState == 4 ) { // request complete var chat_div = document.getElementById( 'chat' ); var xmldoc = receiveReq.responseXML; var msg_nodes = xmldoc.getElementsByTagName( 'message' ); var n_msg = msg_nodes.length; for( i = 0; i < n_msg; i++ ) { alert(i + "," + n_msg); var user_node = msg_nodes[ i ].getElementsByTagName( 'user' ); var time_node = msg_nodes[ i ].getElementsByTagName( 'time' ); var text_node = msg_nodes[ i ].getElementsByTagName( 'text' ); alert(user_node[0].firstChild.nodeValue); //Display message chat_div.innerHTML += user_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += time_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += text_node[ 0 ].firstChild.nodeValue + "<br /><br />"; } } } And again, the whole script if you want it... Code: <script type="text/javascript"> //Credits// //Help: Greg (Gjslick) //Code example: http://www.dynamicajax.com/fr/AJAX_Driven_Web_Chat_Backend-271_290_291_296.html // Declare Global Variables var lastMess; var sendReq; var receiveReq; var mTimer; // Initialize Global Variables (on page load) function init() { lastMess = 0; sendReq = getXmlHttpRequestObject(); receiveReq = getXmlHttpRequestObject(); mTimer; } function getXmlHttpRequestObject() { if( window.XMLHttpRequest ) { return new XMLHttpRequest(); // code decent browsers like Firefox, Chrome, Opera, Safari. And IE7+... } else if( window.ActiveXObject ) { return new ActiveXObject( 'Microsoft.XMLHTTP' ); //Code for crap like IE } else { var statusEl = document.getElementById( 'p_status' ); statusEl.innerHTML = "Status: Could not create XmlHttpRequest Object, please upgrade your browser!"; return null; } } function getMessage() { //var url = "scripts/get_data.php?uid=<?=$uid?>&m=" + lastMess + "&chat=1"; var url = "testXMLdoc.xml"; receiveReq.open("GET",url,true); receiveReq.onreadystatechange = manageMessage; receiveReq.send( null ); lastMess++; } function manageMessage() { if( receiveReq.readyState == 4 ) { // request complete var chat_div = document.getElementById( 'chat' ); var xmldoc = receiveReq.responseXML; var msg_nodes = xmldoc.getElementsByTagName( 'message' ); var n_msg = msg_nodes.length; for( i = 0; i < n_msg; i++ ) { alert(i + "," + n_msg); var user_node = msg_nodes[ i ].getElementsByTagName( 'user' ); var time_node = msg_nodes[ i ].getElementsByTagName( 'time' ); var text_node = msg_nodes[ i ].getElementsByTagName( 'text' ); alert(user_node[0].firstChild.nodeValue); //Display message chat_div.innerHTML += user_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += time_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += text_node[ 0 ].firstChild.nodeValue + "<br /><br />"; } } } </script> And here is the XML file (test doc for now): Code: <?xml version="1.0" ?> <root> <message id="1"> <user></user> <text>testing stupid chat thing</text> <time>0000-00-00 00:00:00</time> </message> <message id="2"> <user></user> <text>dsadasfsdfsggsdgrgsdgfd</text> <time>2010-04-22 19:17:16</time> </message> </root> 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 Problem/Error: JavaScript/AJAX not returning values correctly... The JavaScript/AJAX is printing "null" into the chat_div where the tag name is "user". But in those tags there is actually data, this data is a link. I am thinking that it may be returning the first childNode which would be the <a>? I don't fully understand nodes, but I have had a quick read about them. PHP: PHP Code: <?php //Headers header("Expires: Mon, 01 Dec 1990 05:00:00 GMT" ); header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" ); header("Pragma: no-cache" ); header("Content-Type: text/xml; charset=utf-8"); require("connect.php"); mysql_select_db($dbname, $con); //Variables $ses = explode(".", $_SESSION['user']); //User ID of user currently logged in $sid = $ses[2]; //Number of last message which was displayed, if does not exist or has no value then //last message will be 0. $last_mess = (isset($_GET['m']) && $_GET['m'] != "") ? $_GET['m'] : 0; $last_mess = mysql_real_escape_string($last_mess); $chat = mysql_real_escape_string($_GET['chat']); //Counter for counter number of errors $i = 1; //Send message if (isset($_POST['message']) && $_POST['message'] != "") { //Variables $chat = mysql_real_escape_string($_GET['chat']); $message = mysql_real_escape_string($_GET['message']); $query = "INSERT INTO message (chat_id, user_uid, recipient_uid, message, post_time) VALUES (". $chat.", ".$sid.", ".$rid.", ".$message.", NOW())"; mysql_query($query); } //Get current chat if (isset($_GET['chat'])) { $xml = '<?xml version="1.0" ?><root>'; $query = "SELECT * FROM message WHERE chat_id = ".$chat." AND msg_id > ".$last_mess; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { //Get name of sender $get_name_query = "SELECT * FROM users WHERE uid = '".$row['user_uid']."' OR uid = '".$row['recipient_uid']."'"; $get_name = mysql_query($get_name_query); if (!$get_name) { //If there is no result display error echo "Error $i: Error getting usernames! <br /> Query: $get_name_query <br />MySQL Error: ".mysql_error(). "<br /><br />"; $i++; } //While result is being got get first name and upper case first letter. while ($row2=mysql_fetch_array($get_name)) { $name = explode(".",$row2['full_name']); $first_name = $name[0]; $userid = $row2['uid']; $sent_by = "<a href=\"../profile.php?user=".$userid."\">".ucfirst($first_name)."</a>"; } //Write message contents $xml .= '<message id="' . $row['msg_id'] . '">'; $xml .= '<user>' . $sent_by . '</user>'; $xml .= '<text>' . $row['message'] . '</text>'; $xml .= '<time>' . $row['post_time'] . '</time>'; $xml .= '</message>'; } $xml .= '</root>'; echo $xml; } ?> JavaScript/AJAX: Code: function getMessage() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { var url = "scripts/get_data.php?uid=<?=$uid?>&m=" + lastMess + "&chat=1"; receiveReq.open("GET", url, true); receiveReq.onreadystatechange = manageMessage; receiveReq.send( null ); lastMess++; } } function manageMessage() { if( receiveReq.readyState == 4 ) { // request complete var chat_div = document.getElementById( 'chat' ); var xmldoc = receiveReq.responseXML; var msg_nodes = xmldoc.getElementsByTagName( 'message' ); var n_msg = msg_nodes.length; for( i = 0; i < n_msg; i++ ) { var user_node = msg_nodes[ i ].getElementsByTagName( 'user' ); var time_node = msg_nodes[ i ].getElementsByTagName( 'time' ); var text_node = msg_nodes[ i ].getElementsByTagName( 'text' ); //Display message chat_div.innerHTML += user_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += time_node[ 0 ].firstChild.nodeValue + "<br />"; chat_div.innerHTML += text_node[ 0 ].firstChild.nodeValue + "<br /><br />"; } } } More info: The PHP is displaying the data properly, like so: XML: Code: <root> <message id="1"> <user> <a href="../profile.php?user=4">Nicholas</a> </user> <text>testing stupid chat thing</text> <time>0000-00-00 00:00:00</time> </message> <message id="2"> <user> <a href="../profile.php?user=4">Nicholas</a> </user> <text>dsadasfsdfsggsdgrgsdgfd</text> <time>2010-04-22 19:17:16</time> </message> <message id="3"> <user> <a href="../profile.php?user=4">Nicholas</a> </user> <text>gfgdgsegegsgfawdfwdfasfa</text> <time>2010-04-14 17:28:07</time> </message> </root> What is being displayed on the page: Code: null 0000-00-00 00:00:00 testing stupid chat thing null 2010-04-22 19:17:16 dsadasfsdfsggsdgrgsdgfd null 2010-04-14 17:28:07 gfgdgsegegsgfawdfwdfasfa Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script language="javascript" type="text/javascript"> alert (document.body); </script> </head> <body> </body> </html> EDIT: moved script to after body, and now it works. Not the way it should be done I think ? 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'm trying to build this grease monkey script, which runs on all pages, and simply deletes all iframes that have no content loaded in them. I have a hosts file with many ad servers which are blocked. This leaves ugly holes in the page and I am trying to remove these empty iframes. Plz help |