JavaScript - Getelementbyid Fails With Null
I cant figure out why this doesnt work - Firefox says:
Error: document.getElementById("test") is null Source File: file:///Users/briantoovey/test.html Line: 10 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> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Rotating Quotes</title> </head> <body> <script type="text/javascript"> document.getElementById("test").innerHTML = 'eat it'; </script> <div id="test"></div> </body> </html> Similar TutorialsI have a form that is used to insert a new classified ad or to update an existing ad. When the submit button is pressed a javascript function is called to validate the fields. Some of the fields are set as required. If the field is empty ( as form[i].value = '' ) then this sets an error flag and after all fields have been tested will display an alert and each field that has an error will be highlighted in red. This works great when a new ad is being created, but when the ad is being updated, and a required field is erased then it doesn't popup as an error, as if the script is just ignoring it. Here is the code snipit: Code: function submitbutton(mfrm) { var me = mfrm.elements; var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i"); var r_num = new RegExp("[^0-9\.,]", "i"); var r_email = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}$" ,"i"); var errorMSG = ''; var iserror=0; // set notification background color var warnColor = '#<?php echo $this->error_color; ?>'; // loop through all input elements in form for (var i=0; i < me.length; i++) { // check if element is mandatory; here mosReq="1" if ((me[i].getAttribute('mosReq') == 1)&&(me[i].style.visibility != 'hidden')) { if (me[i].type == 'radio' || me[i].type == 'checkbox') { var rOptions = me[me[i].getAttribute('name')]; var rChecked = 0; if(rOptions.length > 1) { for (var r=0; r < rOptions.length; r++) { if (rOptions[r].checked) { rChecked=1; } } } else { if (me[i].checked) { rChecked=1; } } if(rChecked==0) { errorMSG += me[i].getAttribute('mosLabel').replace(' ',' ') + ' : <?php echo html_entity_decode(addslashes(JText::_('COM_CLASSIFIEDSREDUX_REGWARN_ERROR')),ENT_QUOTES); ?>\n'; // notify user by changing background color, in this case to red me[i].style.background = warnColor; iserror=1; } } if ((me[i].value == '') || (me[i].value.length < 2)) { errorMSG += me[i].getAttribute('mosLabel').replace(' ',' ') + ' : <?php echo html_entity_decode(addslashes(JText::_('COM_CLASSIFIEDSREDUX_REGWARN_ERROR')),ENT_QUOTES); ?>\n'; me[i].style.background = warnColor; iserror=1; } } } if(iserror==1) { alert(errorMSG); return false; } } Im trying to do a vertical movment of banner to follow the to scrolling screen <script type="text/javascript"> var ban = document.getElementById("left_ads"); var scrn = document.getElementById("bodyinfo"); if (ban.style.top < scrn.offsetTop) { ban.style.top += 1; } if (ban.style.top > scrn.offsetTop) { ban.style.top -= 1; } </script> whe <div Id="left_ads"></div> <body ID="bodyinf"> and in stylesheet: #left_ads{ position: absolute; top: 0px; } but the veriables ban and scrn dont get the value and they are bull so all this fails. using IE+5 Whats wrong plz 10X Tal 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 have an error in my script, but idk where it is..... here is the script: Code: <script type="text/javascript"> var browser = navigator.appName; if (browser=="Netscape") { document.getElementById(msg).style.display="none"; } </script> <div id="msg" style="width:100%;padding:3px;position:fixed;top:0px;left:0px;background:red;">Please install <a href="http://www.mozilla.org/sk/firefox/">Mozilla Firefox</a> to view this page normally.</div> I have a button you should be able to click on it once and have one new page open into ID 1 then you should be able to click on it again and have a second page load into ID 2. Sometimes it works sometimes it doesnt. I have no idea why. The script is below. I highlighted the bits I think relevant. When it doesn't work I get the error message: document.getElementById(...)' is null or not an object Mainpage: Code: <?php session_start(); if (!(isset($_SESSION[login]) && $_SESSION[login] !='')){ header ("Location: Welcome.php"); } $Sfullname=$_SESSION['fullname']; $SMyPId=$_SESSION['MyPId']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <title>Chat</title> <head> <link rel="stylesheet" type="text/css" href="eightysixdegreesstyle.css" /> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function (){ $('#submitchat1, #submitchat2, #submitchat3, #submitchat4, #submitchat5').live('click',function(){ var btn = $(this).attr('id'); var Frm; if(btn == 'submitchat1'){ Frm = '#chatmessage1'; } else if(btn == 'submitchat2'){ Frm = '#chatmessage2'; } else if(btn == 'submitchat3'){ Frm = '#chatmessage3'; } else if(btn == 'submitchat4'){ Frm = '#chatmessage4'; } else if(btn == 'submitchat5'){ Frm = '#chatmessage5'; } var data = $(Frm).serialize(); $.post ('insertChat.php',data, function(){ $(Frm).each (function(){ this.reset(); }); return false; }); }); $('#maximizeChat1, #maximizeChat2, #maximizeChat3, #maximizeChat4, #maximizeChat5').live('click',function(){ var btn = $(this).attr('id'); var Display; if(btn == 'maximizeChat1'){ Display = '#ChatDisplayOne'; } else if(btn == 'maximizeChat2'){ Display = '#ChatDisplayTwo'; } else if(btn == 'maximizeChat3'){ Display = '#ChatDisplayThree'; } else if(btn == 'maximizeChat4'){ Display = '#ChatDisplayFour'; } else if(btn == 'maximizeChat5'){ Display = '#ChatDisplayFive'; } $(Display).slideToggle("slow"); }); }); </script> <style type="text/css"> /*<![CDATA[*/ #chat1 { display:block; } #chat2 { display:block; } #chat3 { display:block; } #chat4 { display:block; } #chat5 { display:block; } /*]]>*/ </style> <script type="text/javascript"> function loadChat(File,ID,Msg,TID,Cile){ loadChatComplex(File,ID,Msg); delay = setTimeout(function(){loadChatRefresh(Cile,TID,Msg)},5000); } </script> <script type="text/javascript"> function OpenChat(File,LID,Msg,Dsg,Sile,SID,Wile,WID,Wsg){ loadChatComplex('getUpdateNew.php','txtHingNoNew',Dsg); breath = setTimeout(function(){loadChatTalkComplex(File,LID,Msg)},1000); lalker = setTimeout(function(){loadChatTalkComplex(Sile,SID,Wsg)},3000); talker = setTimeout(function(){loadChatTalkRefresh(Wile,WID,Wsg)},5000); } </script> <script type="text/javascript"> function loadChatCheck(File,ID,Tile,TID){ loadQuickCheck(File,ID); dodo = setTimeout(function(){loadQuickMessageCheck(Tile,TID)},3000); } </script> <script type="text/javascript"> function closeChat(ID,File,LID,Msg){ loadChatComplex(File,LID,Msg); document.getElementById(ID).style.display="none"; } </script> <script type="text/javascript"> function loadChatComplex(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <script type="text/javascript"> function loadChatTalkComplex(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <script type="text/javascript"> function loadChatRefresh(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; ticker = setInterval(function(){loadChatRefresh(File,ID,Msg)},3000); } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <script type="text/javascript"> function loadChatTalkRefresh(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; ticker = setInterval(function(){loadChatRefresh(File,ID,Msg)},3000); } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <script type="text/javascript"> function loadChatBasic(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> <script type="text/javascript"> function loadQuickCheck(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; malaky = setInterval(function(){loadQuickCheck(File,ID)},5000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> <script type="text/javascript"> function loadQuickMessageCheck(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; whistle = setInterval(function(){loadQuickCheck(File,ID)},5000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> </head> <body onload="loadChatCheck('getCheckNewMessages.php','txtHintCheckNewMessage','getFriendsOnline.php','txtHintShowFriends')"> <div class="mainpage"> <table border="0" width="100%"> <tr> <td> <h1>Thanks</h1> <?php echo "Hi " . $Sfname;?> <br /> </td> <td> <div class="right"> <input type="text" name="search" class="input" value="search" size="40" onclick="clearMe(this)" onkeyup="ShowHint(this)"> <br /> <div id="txtMainSearchHint"></div> </div> </td> </tr> </table> <hr /> <br /> <br /> <div> <div class="pageleft"> <p>Friends Online:</p> <br /></br /> <div id="txtHintShowFriends"></div> <div id="txtHintEndChat"></div> <div id="txtHintCheckNewMessage"></div> <div id="txtHingNoNew"></div> <div id="txtHintClearChat"></div> <br /><br /> <input type="button" value="Clear All" onclick="loadChatBasic('getClearChat.php','txtHintClearChat')" /> <br /><br /> <div class="chat1" id="chat1">Space Holder</div> <div class="chat2" id="chat2">Space Holder</div> <div class="chat3" id="chat3">Space Holder</div> <div class="chat4" id="chat4">Space Holder</div> <div class="chat5" id="chat5">Space Holder</div> <br /> <br /> </div> <div class="pageright"> <?php include("SideBar.php"); ?> </div> </div> <div class="clear"></div> <br /> <br /> <?php include("footer.php"); ?> </div> getFriendsOnline.php PHP Code: <?php session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] !='')){ header ("Location: Welcome.php"); } $SMyPId=$_SESSION['MyPId']; include("dbconnect.php"); $result = mysql_query("SELECT *, signedin.PId as SIPId FROM signedin INNER JOIN friends ON signedin.PId=friends.invited OR signedin.PId=friends.invitee WHERE ((friends.invitee={$SMyPId} AND friends.statae='accepted') OR (friends.invited={$SMyPId} AND friends.statae='accepted')) AND signedin.LogOff IS NULL AND signedin.PId !={$SMyPId}"); while($row = mysql_fetch_array($result)){ $mugwort= $mugwort . ';' . $row['SIPId']; } $motherwort=explode(';',$mugwort); foreach ($motherwort as $mulberry){ $result = mysql_query("SELECT COUNT(*) as divonecount FROM chat WHERE chatter='{$SMyPId}' AND chatterspace='chat1' AND EndDate IS NULL"); $row = mysql_fetch_assoc($result); $divonecount=$row['divonecount']; $result = mysql_query("SELECT COUNT(*) AS divtwocount FROM chat WHERE chatter='{$SMyPId}' AND chatterspace='chat2' AND EndDate IS NULL"); $row = mysql_fetch_assoc($result); $divtwocount=$row['divtwocount']; $result = mysql_query("SELECT COUNT(*) AS divthreecount FROM chat WHERE chatter='{$SMyPId}' AND chatterspace='chat3' AND EndDate IS NULL"); $row = mysql_fetch_assoc($result); $divthreecount=$row['divthreecount']; $result = mysql_query("SELECT COUNT(*) AS divfourcount FROM chat WHERE chatter='{$SMyPId}' AND chatterspace='chat4' AND EndDate IS NULL"); $row = mysql_fetch_assoc($result); $divfourcount=$row['divfourcount']; $result = mysql_query("SELECT COUNT(*) AS divfivecount FROM chat WHERE chatter='{$SMyPId}' AND chatterspace='chat5' AND EndDate IS NULL"); $row = mysql_fetch_assoc($result); $divfivecount=$row['divfivecount']; if($divonecount=='0'){ $showchat='chat1'; } elseif ($divtwocount=='0'){ $showchat='chat2'; } elseif ($divthreecount=='0'){ $showchat='chat3'; } elseif ($divfourcount=='0'){ $showchat='chat4'; } elseif ($divfivecount=='0'){ $showchat='chat5'; } [COLOR="Red"] if($showchat=='chat1'){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="OpenChat(\'chatheader1.php\',\'chat1\',\'chat=' . $nightshade . '\',\'ChatID=0\',\'getDisplayChat1.php\',\'ChatDisplayOne\',\'getThisChat1.php\',\'displaytalkOne\',\'artemis=' . $nightshade . '\')" /><br /> '; } }elseif($showchat=='chat2'){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="OpenChat(\'chatheader2.php\',\'chat2\',\'chat=' . $nightshade . '\',\'ChatID=0\',\'getDisplayChat2.php\',\'ChatDisplayTwo\',\'getThisChat2.php\',\'displaytalkTwo\',\'artemis=' . $nightshade . '\')" /><br /> '; } }elseif($showchat=='chat3'){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="OpenChat(\'chatheader3.php\',\'chat3\',\'chat=' . $nightshade . '\',\'ChatID=0\',\'getDisplayChat3.php\',\'ChatDisplayThree\',\'getThisChat3.php\',\'displaytalkThree\',\'artemis=' . $nightshade . '\')" /><br /> '; } }elseif($showchat=='chat4'){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="OpenChat(\'chatheader4.php\',\'chat4\',\'chat=' . $nightshade . '\',\'ChatID=0\',\'getDisplayChat4.php\',\'ChatDisplayFour\',\'getThisChat4.php\',\'displaytalkFour\',\'artemis=' . $nightshade . '\')" /><br /> '; } }elseif($showchat=='chat5'){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="OpenChat(\'chatheader5.php\',\'chat5\',\'chat=' . $nightshade . '\',\'ChatID=0\',\'getDisplayChat5.php\',\'ChatDisplayFive\',\'getThisChat5.php\',\'displaytalkFive\',\'artemis=' . $nightshade . '\')" /><br /> '; } }else{ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; echo '<img src="thumbs/' . $row['pphoto'] . '" width="30px" /><input type="button" class="button10" name="frol" id="frol" value="' . $row['fullname'] . '" onclick="alert(\'You have reached your IM capacity, please close a chat box\')" ;> '; } } } [/COLOR] echo '<br /><div class="clear"></div><br /><br />'; mysql_close($con); ?> Or you can see it at : Website: eighty-sixdegrees.com Then Sign in; Username: guest@eighty-sixdegrees.com Password: abcdefgh123456 Click on chat in the header menu then wait five seconds for the boxes to load. 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 I'm getting the following problem. The reason is that the object appears through AJAX. But if I choose it NOT to appear it gives this problem. How can I avoid this? I put an if statement inline Code: if(document.getElementById('vsbtitle_1').value!=null){ thisurlext+='&btitle1='+document.getElementById('vsbtitle_1').value; } But it doesn't help. Quote: Error: document.getElementById("vsbtitle_1") is null Source File: javascript:%20var%20file='forforum.php';%20var%20thisurlext='?type=forforum&btitle0='+document.getEl ementById('vsbtitle_0').value;%20if(document.getElementById('vsbtitle_1').value!=null){thisurlext+=' &btitle1='+document.getElementById('vsbtitle_1').value;%20}%20var%20checkedlength=0;%20thisurlext+=' &checkresult0=';%20for(i=0;i<document.getElementsByName('checkresult_0').length;++i){if(document.get ElementsByName('checkresult_0')[i].checked){thisurlext+=document.getElementsByName('checkresult_0')[i].value;checkedlength++;if(i+1<document.getElementsByName('checkresult_0').length){if(document.getEle mentsByName('checkresult_0')[i+1].checked){thisurlext+='+';}}}};%20thisurlext+='&checkresult1=';%20for(i=0;i<document.getElementsByNa me('checkresult_1').length;++i){if(document.getElementsByName('checkresult_1')[i].checked){thisurlext+=document.getElementsByName('checkresult_1')[i].value;checkedlength++;if(i+1<document.getElementsByName('checkresult_1').length){if(document.getEle mentsByName('checkresult_1')[i+1].checked){thisurlext+='+';}}}};var%20getKeyURL='';%20for(a=0;%20a<document.getElementById('txtid').v alue;%20a++){if(document.getElementById('txtarea_'+[a]).value!=%20''){getKeyURL+='&txtarea'+[a]+'=';}getKeyURL+=document.getElementById('txtarea_'+[a]).value;}var%20thisnewurlext=file+thisurlext+getKeyURL;%20forForum(); Line: 1 Hey all, For the below code, I'm just trying to create a simple toggle menu for a Table of Contents. However, when page loads, I get document.gelementbyid('sidebar') is null even though it's clearly there and if I move script to below markup, it will also give me a hideElements() is not a function error, even though it clearly is. Code: <script type="text/javascript"> (function(){ var headers = document.getElementById("sidebar").childNodes; for(var i=0; i < headers.length; i++){ hideElements(headers[i]); if(headers[i].nodeName == "h1"){ headers[i].childNodes[0].onclick = function(){ hideElements(headers[i]); this.parentNode.nextSibling.style.display = "block"; return false; } } } var hideElements = function(element){ if(element.nodeName == "UL") element.style.display = "none"; } })(); </script> <body> <a name="top"></a> <div id="masthead"> <h1>This is the Help Page</h1> </div> <div id="sidebar"> <h1><a href="chapter1"> Info</a></h1> <ul> <li><a href="#section1">Section 1</a></li> <li><a href="#section2">Section 2</a></li> <li><a href="#section3">Section 3</a></li> </ul> <h1><a href="chapter2"> Info</a></h1> <ul> <li><a href="#section4">Section 4</a></li> <li><a href="#section5">Section 5</a></li> <li><a href="#section6">Section 6</a></li> </ul> </div> <div id="content"> <h1 id="section1">Section 1</h1> <p> </p> <a href="#top">Back to Top</a> <h1 id="section2">Section 2</h1> <p> </p> <a href="#top">Back to Top</a> <h1 id="section3">Section 3</h1> <p> </p> <a href="#top">Back to Top</a> </div> </body> Thanks for any response. Hi 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! 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 Here is the PHP: PHP Code: <?php if (($totalRows_getDie = mysql_num_rows($getDie)) != NULL) { echo "Die Category: <select name='DieCatId' class='dropMenu' id='DieCatId' onchange='jobDieChange(this.value)'> <option value='NULL'></option>"; do { echo "<option value='".$row_dieCatList['DieCatID']."'"; if (!(strcmp($row_dieCatList['DieCatID'], $row_getDie['DieCatID']))) {echo "selected=\"selected\"";} echo ">".$row_dieCatList['DieCatDesc']."</option>"; } while ($row_dieCatList = mysql_fetch_assoc($dieCatList)); $rows = mysql_num_rows($dieCatList); if($rows > 0) { mysql_data_seek($dieCatList, 0); $row_dieCatList = mysql_fetch_assoc($dieCatList); } echo "</select> <a href='popup.php?getpage=dieins' onclick='window.open(this.href, 'popupwindow', 'width=770,height=675,scrollbars,resizable'); return false;'>Add Die</a><br />"; echo "Die: <select name='DieID' class='dropMenu' id='DieID'>"; if ($totalRows_getDie != 0) { echo "<option value='".$row_getDie['DieID']."'>".$row_getDie['DieDesc']."</option>"; } echo "</select><br />"; echo "<input type='hidden' name='DiecutID' value='".$row_getDie['DiecutID']."' />"; } ?> And the JS: Code: var xmlhttpJDie; function jobDieChange(str) { xmlhttpJDie=GetXmlHttpObject(); if (xmlhttpJDie==null) { alert ("Browser does not support HTTP Request"); return; } var url="/scripts/jobdie.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttpJDie.onreadystatechange=JobDieGet; xmlhttpJDie.open("GET",url,true); xmlhttpJDie.send(null); } function JobDieGet() { if (xmlhttpJDie.readyState==4) { document.getElementById("DieID").innerHTML=xmlhttpJDie.responseText; } } In all browsers except IE, it works fine, but IE gets a Script error and won't update the second select. I've gone over this so many times I'm cross eyed! If someone could please help me figure out why IE doesn't like this I would appreciate it. Thank you! This is the code part that fails it's if check. Code: while (n<=30) { var slot='#slot'+n; $( slot ).data({no: n, id: itemId[i], name: itemName[i], equip: itemEquip[i], lvl: itemLvl[i], bonus: itemBonus[i], rstr: itemRStr[i], rdef: itemRDef[i]}); $( slot ).draggable({ handle: slot, stack: slot, revert: "invalid", snap: "div#"+itemEquip[i], snapMode: 'inner', start: function(event, ui) { $('div#'+$(this).data('equip')).css({'border': '2px dashed #0066CC', 'background': 'rgba(255,255,255,0.2)'}) .droppable ({ drop: function(event, ui) { if (pLvl>=$('.ui-draggable-dragging').data('lvl') && pStr>=$('.ui-draggable-dragging').data('rstr')) { alert(pLvl+", "+$('.ui-draggable-dragging').data('lvl')); $('.ui-draggable-dragging').css({'display':'none'}); $('div#'+$('.ui-draggable-dragging').data('equip')).html ( "<img src='items/equipped/"+$('.ui-draggable-dragging').data('name')+$('.ui-draggable-dragging').data('id')+".png' />" ) $.ajax({type:"GET", url:"items/change.php", data:"id="+$('.ui-draggable-dragging').data('id')+"&no="+$('.ui-draggable-dragging').data('no'), cache:false, timeout:5000, error: function() { $('div.nogood').html ( "There was an error. Please inform us about it in the forum." ).css({'width':'400px','margin-left':'-200px'}); $( 'div.nogood' ).fadeIn(500, away); function away() { $( 'div.nogood' ).delay(2000).fadeOut(500); }; } }); } else { alert("HUh"); $( 'div.nogood' ).fadeIn(500, away).css({'width':'400px','margin-left':'-200px'});; $('.ui-draggable-dragging').draggable({revert: true}); if (pLvl<$('.ui-draggable-dragging').data('lvl')) { alert("Good"); } else if (pStr<$('.ui-draggable-dragging').data('rstr')) { $('div.nogood').html("Not enough strength.") } function away() { $( 'div.nogood' ).delay(1400).fadeOut(500); }; } } }); }, stop: function(event, ui) { $('div#'+$(this).data('equip')).css({'border':'none', 'background':'transparent'}).droppable("destroy"); } }); n++; i++; } This if comparison if (pLvl>=$('.ui-draggable-dragging').data('lvl') && pStr>=$('.ui-draggable-dragging').data('rstr')) somehow goes through. After the if statement I check the values with the alert but it displays 5 for pLvl and 10 for the draggables data (which are the correct numbers) so can anyone tell me why does this if statement still go through when pLvl is lower? Hi, does 'focus' method show a 'stable' result? i call this method on a node -- if this one is not absolutely positioned -- it seems nothing happens so ① does this method only apply to absolutely positioned element? also, in FF, aNode.focus() has no effect whereas in IE document will scroll until that node is visible if the node is partially invisible at the bottom. ②is this a bug in FF? here is the code Code: <div style="position:absolute; left:50px; top: 700px" onclick="this.focus();"> yepsfagadgre<br />agefderdsf<br />agefderdsf<br />agefderdsf</div> scroll the document until the text is half-visible at the bottom. click on it -- in IE it will scroll up while in FF nothing happens besides, if it is not absolutely positioned, nothing happens either~~~ thx in advance i cant get collission detection to work. i tryed but it always caused an infinite loop. heres the code. Code: <html> <!-- main file.--> <head> <title>lightning generator</title> </head> <body> <canvas id='world' width='500' height='500' style='border: 1px solid black; padding:0;'></canvas> <script type="text/javascript" src='world.js'></script> <script type='text/javascript' src='eC.js'></script> <script type='text/javascript' src='world.ground.js'></script> <script type='text/javascript'> world.bolt = { } ; world.bolt.paths = []; // main obj inits world.bolt.draw = function(){ var x, y; for( var id = 0; id <= world.bolt.draw.num; id ++ ){ world.ctx.moveTo( world.bolt.paths[id].x[world.bolt.paths[id].x.length-1], world.bolt.paths[id].y[world.bolt.paths[id].y.length-1] ); var mdx=Math.floor(Math.random()*world.bolt.paths[id].mdx); x = world.bolt.paths[id].x[world.bolt.paths[id].iters] + ((Math.random()<Math.random())?mdx:-mdx); y = ++ world.bolt.paths[id].iters; world.bolt.paths[id].x.push( x ); world.bolt.paths[id].y.push( y ); world.ctx.strokeStyle = world.bolt.paths[id].color; world.ctx.lineTo( x, y ); world.ctx.stroke(); //world.ctx.beginPath(); } if(x%3==0){ world.ctx.fillStyle=world.skyColor; world.ctx.fillRect(0,0,world.w,world.h);} } world.bolt.draw.num=-1; world.bolt.cpath = function( x, y, mdx, srate, id, color ){ world.bolt.paths[id] = { } ; world.bolt.paths[id].iters = 0; world.bolt.paths[id].x = []; world.bolt.paths[id].y = []; world.bolt.paths[id].x[0] = x; world.bolt.paths[id].y[0] = y; world.bolt.paths[id].mdx = mdx; world.bolt.paths[id].srate = srate; world.bolt.paths[id].color = color; world.bolt.draw.num += 1; } world.bolt.cpath(250,0, 5,5,0,'rgba(255,255,150,.5)'); window.setInterval(world.bolt.draw,100) window.setTimeout('world.bolt.cpath(125,0,5,5,1,"rgba(255,10,0,.5)")',1000); </script> </body> </html> Code: //world.js var world = { skyColor:'rgba(0,0,100,.009)' } ; world.canvas = document.getElementById( 'world' ) world.canvas.cstyle = document.defaultView.getComputedStyle( world.canvas, null ) world.w = parseInt( world.canvas.cstyle.width, 10 ); world.h = parseInt( world.canvas.cstyle.height, 10 ); world.ctx = world.canvas.getContext( '2d' ); finally, Code: // world.ground.js world.ground = { } ; world.ground.level = []; world.ground.make = function( GArray, length ){ world.ctx.strokeStyle = '#000000'; world.ground.level = []; world.ctx.fillStyle = '#FFF'; world.ctx.fillRect( 0, 0, world.w, world.h ); world.ground.level = GArray; for ( world.ground.make.i = 0; world.ground.make.i <= length; world.ground.make.i ++ ){ if ( GArray[world.ground.make.i + 1] === undefined ){ GArray[world.ground.make.i + 1] = GArray[world.ground.make.i]; } world.ctx.moveTo( world.ground.make.i, ( world.h ) ); world.ctx.lineTo( world.ground.make.i, ( world.h - GArray[world.ground.make.i] ) ); } world.ctx.stroke(); world.ctx.beginPath(); } ; world.ground.create = function( func, width ){ func = ec( func ); if( func === false ){ alert( 'Pass equation as a string without the "y=", "f(x)=", "g(x)=" or similar.' ); return world; } if( func == 'perspicaciousness' ){ return world; } var temp = []; for( var x = 0; x <= width; x ++ ){ temp[x] = eval( func ); } world.ground.make( temp, width ); } ; world.ground.create.test='4'; world.ground.create( world.ground.create.test, 500 ); in the end of world.bolt.cpath,there should be a way to use the local varis X and Y, and world.ground.js's world.ground.level[] to detect it. sorry for the gigantic length. thanks in advanced. the jsnerd http://edison.seattlecentral.edu/~dw.../testform2.htm http://edison.seattlecentral.edu/~dw...ude/util-dw.js Could someone check js and tell me how I can get the form to validate it hangs up on password. So, I know there are lots of threads out there about the jQuery validation plugin and people having issues with IE7, but most of them come down to syntax issues with a closing comma or what not. With that said, I have milled over this code of least a full day now and still have no idea why it fails in IE (all versions) http://jsfiddle.net/rM3ej/4/ Can anyone give me some ideas or insight why this would completely fail? Thanks in advanced. I have a form that passes values to a next step. It has two sub divs that show depending on what's selected from the dropdowns in the top two divs. I'm trying to keep the selected sub divs open if the user hits previous step. The divs stay open in FF but not in IE. Any ideas? dropdowns Code: <table border="0" cellspacing="0" cellpadding="2"> <tr valign="top"> <td align="right">Morning:</td> <td><select name="wcsave_10_msession" id="wcsave_10_msession" size="1" onblur="CheckField(this.form,this,'');" onchange="display1(this,'Concurrent sessions 1-6');"> <option value="" selected="selected">Choose one</option> <option value="Mastery session 1 - Computer Lab: Searching Essentials"> <strong>Mastery session 1</strong> - Computer Lab: Searching Essentials</option> <option value="Concurrent sessions 1-6">Concurrent sessions 1-6</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Concurrent sessions 1-6" style="display: none;"> <table class="special"> <tr valign="top"> <td>Choose a session for each time slot.<br /> (9:15 a.m. - 10:15 a.m.)<br /><select name="wcsave_10_session_mconc1" id="wcsave_10_session_mconc1"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 1 - IRB 101 for Research Nurses">Concurrent session 1 - IRB 101 for Research Nurses</option> <option value="Concurrent session 2 - A Research Poster Contest as a Tool to Learn About Research/EBP">Concurrent session 2 - A Research Poster Contest as a Tool to Learn About Research/EBP</option> <option value="Concurrent session 3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature">Concurrent session 3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature</option> </select> </td> </tr> <tr valign="top"> <td>(10:30 a.m. - 11:30 a.m.)<br /><select name="wcsave_10_session_mconc2" id="wcsave_10_session_mconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 4 - Making Sense of Statistics When Reading Research">Concurrent session 4 - Making Sense of Statistics When Reading Research</option> <option value="Concurrent session 5 - Original Research Presentations">Concurrent session 5 - <em>Original Research Presentations</em></option> <option value="Concurrent session 6 - IRB Considerations with Vulnerable Populations">Concurrent session 6 - IRB Considerations with Vulnerable Populations</option> </select> </td> </tr> </table> </div> </td> </tr> <tr valign="top"> <td colspan="2"> </td> </tr> <tr valign="top"> <td align="right">Afternoon:</td> <td><select name="wcsave_10_asession" id="wcsave_10_asession" size="1" onblur="CheckField(this.form,this,'');" onchange="display2(this,'Concurrent sessions 7-12');"><!--showDiv(this.value)--> <option value="" selected="selected">Choose one</option> <option value="Mastery session 2 - Beyond the Basics of Searching!"><strong>Mastery session 2</strong> - Beyond the Basics of Searching!</option> <option value="Concurrent sessions 7-12">Concurrent sessions 7-12</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Concurrent sessions 7-12" class="hiddenDiv"> <table class="special"> <tr valign="top"> <td>Choose a session for each time slot.<br /> (1:45 p.m. - 2:45 p.m.)<br /><select name="wcsave_10_session_aconc1" id="wcsave_10_session_aconc1"> <option value="" selected="selected">Choose one</option> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 7 - EBP Protocols">Concurrent session 7 - EBP Protocols</option> <option value="Concurrent session 8 - Writing for Publication">Concurrent session 8 - Writing for Publication</option> <option value="Concurrent session 9 - Original Research Presentations">Concurrent session 9 - Original Research Presentations</option> </select> </td> </tr> <tr valign="top"> <td>(3:00 p.m. - 4:00 p.m.)<br /><select name="wcsave_10_session_aconc2" id="wcsave_10_session_aconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 10 - Writing a Research Question Using PICO">Concurrent session 10 - Writing a Research Question Using PICO</option> <option value="Concurrent session 11 - EBP Project Presentations">Concurrent session 11 - EBP Project Presentations</option> <option value="Concurrent session 12 - The Role of the Research Facilitator">Concurrent session 12 - The Role of the Research Facilitators</option> </select> </td> </tr> </table> </div> </td> </tr> </table> javascript: Code: var lastDiv = ""; function showDiv(divName) { var items = document.getElementById('wc_addItem_ADV'); var form = document.getElementById('webcredit'); var total = document.getElementById('Total'); var amount = document.getElementById('amount'); // set checkboxes to 0 for (var i = 0; i < form.elements.length; i++ ) { if (form.elements[i].type == 'checkbox') { form.elements[i].checked = false; document.getElementById(form.elements[i].id).value = "0"; } } total.value = ''; amount.value= ''; // hide last div if (lastDiv) {document.getElementById(lastDiv).className = "hiddenDiv";} //if value of the box is not nothing and an object with that name exists, then change the class if (divName && document.getElementById(divName)) { document.getElementById(divName).className = "visibleDiv"; lastDiv = divName; } } function showInitialDiv() { var selBox = document.getElementById('wcsave_10_session_mconc1'); if (selBox == undefined || selBox == null) return; var val = selBox.options[selBox.selectedIndex].value; if (val == null || val == '') return; showDiv(val); } I only call one of the sub div ID's but it seems to work in FF with no errors. Everything is called with: Code: <body onload="showInitialDiv();"> I have a function called onload that includes this: Code: window.onload=new function(){ ... if (menuletter!=false){ document.cookie="hddrv="+(menuletter)+"; path=/; expires="+exp.toGMTString(); document.enterIndex.src='enter2.gif'; // window.setTimeout("goIndex()",7000); // return false; } ... } <img border="0" name="enterIndex" src="enter1.gif" width="413" height="41"> If I uncomment the two lines and comment the document image swap line, they execute perfectly, so the routine works. But if I try to do the image swap instead of the two commented lines, it doesn't swap. Of course, the image enter1.gif and enter2.gif exist. What am I doing wrong? |