JavaScript - Problem With Newwindow.document.getelementbyid()
Hello, I am having a problem with javascript code:
Code: newWindow.document.getElementByID() where "newWindow" is a new "window" object opened up with an existing file in the same directory as the current file. The complete function looks like this: Code: function showStreamInFullScreenMode(stream_id) { var params = "width=" + screen.width + ", height=" + screen.height + ", top=0, left=0" + "location=no, menubar=no, scrollbars=no," + "resizable=no, toolbar=no, directories=no, fullscreen=yes"; var newWindow = window.open("fullscreenMode.html", "Fullscreen Mode", params, false); var customScript = "initOpenTokSession(\"" + stream_id + "\");"; var scriptElement = newWindow.document.getElementById("customScript"); scriptElement.innerHTML = customScript; if (window.focus) { newWindow.focus(); } } The bolded line of code is what is producing the error: Quote: scriptElement is null Note that the file that is opened (fullscreenMode.html) does indeed have a <script> html element with the id "customScript" so there is no reason why scriptElement should be null. I would appreciate any help anyone could offer. Thanks in advance. Similar TutorialsHello everyone. As lame as this may sound, I can't for the life of me get the document by the id. All looks fine to me, but I get the following error that just simply doesn't make sense. Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) Timestamp: Fri, 15 Jan 2010 01:37:06 UTC Message: Object required Line: 7 Char: 4 Code: 0 Here's the code... Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript"> function doSomething() { var elem = document.getElementById('doFade'); alert(elem.src); } window.onload = doSomething(); </script> </head> <body> <img src="/images/aero.jpg" id="doFade" width="300" height="200" /> </body> </html> i have the code in JS: Code: if(drop_list.value == "zed-catcher/11") { input_box.disabled=false; var catcher_id = document.getElementById('lpm_service_catcher_id'); catcher_id.value = 11; } else input_box.disabled=true; how come the line catcher_id.value = 11; is not setting the value to 11???? i get that catcher_id = null???? pleas help thanks Code: onload=function() {progress1();} var repeat=0; function progress1() { document.getElementById('clib').style.display="inline"; if (repeat<9) { repeat=repeat+1; setTimeout('progress1()',1000); old = document.getElementById('cliba').innerHML; document.getElementById('cliba').innerHML=old+'.'; } else { progress2(); } } var repeata=0; function progress2() { document.getElementById('wlib').style.display="inline"; if (repeata<23) { repeata=repeata+1; setTimeout('progress2()',1000); old = document.getElementById('wliba').innerHML; document.getElementById('wliba').innerHML=old+'.'; } else { progress3(); } } var repeatb=0; function progress3() { document.getElementById('dlib').style.display="inline"; if (repeatb<17) { repeatb=repeatb+1; setTimeout('progress3()',1000); old = document.getElementById('dliba').innerHML; document.getElementById('dliba').innerHML=old+'.'; } else { progress4(); } } var repeatc=0; function progress4() { document.getElementById('slib').style.display="inline"; if (repeatc<4) { repeatc=repeatc+1; setTimeout('progress4()',1000); old = document.getElementById('sliba').innerHML; document.getElementById('sliba').innerHML=old+'.'; } else { progress5(); } } var repeatd=0; function progress5() { document.getElementById('vlib').style.display="inline"; if (repeatd<17) { repeatd=repeatd+1; setTimeout('progress5()',1000); old = document.getElementById('vliba').innerHML; document.getElementById('vliba').innerHML=old+'.'; } else { progress6(); } } var repeate=0; function progress6() { document.getElementById('xlib').style.display="inline"; if (repeate<33) { repeate=repeate+1; setTimeout('progress6()',1000); old = document.getElementById('xliba').innerHML; document.getElementById('xliba').innerHML=old+'.'; } else { pyws(); } } var repeatf=0; function pyws() { document.getElementById('pyws').style.display="inline"; if (repeatf<7) { repeatf=repeat+1; setTimeout('pyws()',1000); old = document.getElementById('pywsa').innerHML; document.getElementById('pywsa').innerHML=old+'.'; } } HI.....idk why it is not working......when I load site, it will start counting, but dots after that .lib files.....look: http://ikoos.tk/load_os/ ......if you don't know what I mean....try to send me a PM. Thank you. here's my javascript code
Code: <script type="text/javascript"> function sel(id){ document.getElementById(id).className="selected"; var getEls = document.getElementById("countrytabs").getElementsByTagName("a"); var getAgn = getEls; for(var i=0; i<getEls.length; i++) { getEls[i].onclick=function() { for (var x=0; x<getAgn.length; x++) { getEls[i].className=getAgn[x].className.replace("selected", ""); } } } } </script> <style> a:hover {color: #FFFF00;} .selected{color: #FFFF00; text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; line-height: 15px; background-color: #ACAAAB; border: 0px none #ACAAAB; height: 20px; width: 125px; text-align: left;} a{color: #333333; text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; line-height: 15px; background-color: #ACAAAB; border: 0px none #ACAAAB; height: 20px; width: 125px; text-align: left;} </style> here's my html code Code: <a href="#" class="selected" id="one" onclick="sel('one')"> Bharati Axa </a><br /> <a href="#" id="two" onclick="sel('two')"> BPCL</a> <br /> <a href="#" id="three" onclick="sel('three')"> Hypercity </a><br /> <a href="#" id="four" onclick="sel('four')"> Idea </a> the problem is when i select a link the first time. it works fine. but when i select another link the next time the script does not work. Basically it works only once when page is loaded and then its not working at all. Its not showing any errors either. don't know whats happing.? Can someone please help me its urgent? Any help will be really gratefull! Hi.. I have problem on how can I automatically display the output from the computation (Demanded Qty * Quantity), after or while I input Demanded Qty. I mean I input Demanded Qty, on below it will display the output also beside the SubItems. Sorry, if i post again my problem, because I have no idea on how can I solve this problem. here is my code: PHP Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function compute_quantity(){ var DemandedQty = document.getElementById('DemandedQty').value; var SubQty = document.getElementById('SubQty').value; var Quantity = document.getElementById('Quantity').value; SubQty = (DemandedQty * Quantity); } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $DemandedQty = $_POST['DemandedQty']; $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; $Items_ = substr($Items, 12, 3); echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border:none;'> </td> <td style='border:none;'> </td> <td style='border: none;'><center><input type='text' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup = compute_quantity()></center></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; $Quantity = $row_sub['Quantity']; echo "<input type='hidden' name='Quantity' id='Quantity' value='$Quantity'>"; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'><center><input type='text' name='SubQty[]' id='SubQty' value='' size='12' style></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td> <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> </tr>"; } } ?> </table> </div> </form> </body> </html> If you don't understand my issue feel free to ask me for further understanding. I'm sorry again I really need to solve this and i tried to google but I can't find the solution. Thank you so much Hi... I got an error: Object Required when I use this code: Code: var SubQty = document.getElementById("SubQty").value; <input class='txt' type='text' name='SubQty[]' id='$joinId' size='12' style= 'border:none;' value=''/> How can I get the value? Thank you My code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> What I'm trying to get are the tag ids separately after I call the callback function. I've been racking my brain for far too long on this one. Here is a shorter version of what I have. I'm using the array's length to count and break into their own lines. How do i get all 9 id="hover_[index]" separately using my array length? PHP Code: var info = Array("bla_1", "bla_2", "bla_3", "bla_4", "bla_5", "bla_6", "bla_7", "bla_8", "bla_9"); function callback(results, status) { if (status == myStatus) { for (var i = 0; i < results.length; i++) { send(results[i]); } } } function send(info) { document.getElementById('results').innerHTML += "<div id='hover_"+info.length+"'>Something</div>"; hover_target = document.getElementById('hover_'+info.length);// how do i get all 9 hover_[index] separately? someEvent.addDomListener(hover_target, 'mouseover', function() { // do something }); } Thank you so much in advance, Frank I have a html file and a separate javascript file. The html file contains: <input type="reset" id = "resetButton" /> I want a message to pop up if the reset button is pressed. So in the js file I have: document.getElementById("resetButton").onclick = doAlert; doAlert is a function that simply does: alert("Do you want to reset?"); I know my separate js file is linked correctly because if I just put in alert("hello"); in the js file then it works. But if I use the document.getElementById thing in the js file, then there is an error. The error, according to the error console, says that "resetButton" is null. Can someone help me? thanks! btw, I'm totally new to programming...and I need to do this for my homework assignment I am writing some javascript that when the user clicks on a link, it hides or displays content inside a div tag. I have been trying to add some code that would only allow for one div tag to be displayed at a time. Here is where I originally got the code (http://www.willmaster.com/library/hi...-to-reveal.php) Whenever I run this code I get this error: Code: Error: document.getElementById(months[x]) is null Source File: /resources/default.js Line: 30 This is the JavaScript that runs when the user clicks the link: Code: <!-- function accordion(tid) { var x; var months = new Array(); months[0]="January"; months[1]="February"; months[2]="March"; months[3]="April"; months[4]="May"; months[5]="June"; months[6]="July"; months[7]="August"; months[8]="September"; months[9]="October"; months[10]="November"; months[11]="December"; for (x in months) { document.getElementById((months[x])).style.display = "none"; } if(document.getElementById(tid).style.display == "none") { document.getElementById(tid).style.display = ""; } else { document.getElementById(tid).style.display = "none"; }} //--> Here is where the javascript is activated from PHP Code: <a href=javascript:accordion('$month2');>$month2</a><br /> <div id='$month2' style='display: none';> Hello $month2 </div> Hi ALL, I am validating a three form field which takes temperature value between 0-50, humidity 1-100 & rainfall 0-200. I am able to see expected result for temperature value but not getting correct value for humidity & rainfall(still one can insert text in it..) Here is my code-: Code: <script type="text/javascript"> function validate_form(thisform) { with (thisform) { if (validate_required(obdate,"Date must be filled out!")==false) { obdate.focus();return false;} } is_leaf_fresh = -1; for (i=0;i < thisform.is_leaf_fresh.length; i++) { if (thisform.is_leaf_fresh[i].checked == true) { //alert("coming into "+thisform.is_leaf_fresh[i].checked); is_leaf_fresh = 1; } } if ((is_leaf_fresh == -1)) { alert("You must select an option for Fresh Leaf!"); return false; } var temp_max; temp_max = document.getElementById("temperature_max").value; if (temp_max != '' ) { var numericExpression = /^[0-9]+$/; if(temp_max.match(numericExpression) && (temp_max>=0 && temp_max<=50)){ return true; } else{ alert("Max Temperature value should be Numeric & between 0 to 50"); document.getElementById("temperature_max").focus(); return false; } } var temp_min; temp_min = document.getElementById("temperature_min").value; if (temp_min != '' ) { var numericExpression = /^[0-9]+$/; if(temp_min.match(numericExpression) && (temp_min>=0 && temp_min<=50)){ return true; } else{ alert("Min Temperature value should be Numeric & between 0 to 50!"); document.getElementById("temperature_min").focus(); return false; } } var rainfall_mm; rainfall_mm = document.getElementById("rainfall_mm").value; if (rainfall_mm != '' ) { var numericExpression = /^[0-9]+$/; if(rainfall_mm.match(numericExpression) && (rainfall_mm>=20 && rainfall_mm<=50)){ return true; } else{ alert("Min Temperature value should be Numeric & between 20 to 50!"); document.getElementById("rainfall_mm").focus(); return false; } } var humidity_mm; humidity_mm = document.getElementById("humidity_mm").value; if (humidity_mm != '' ) { var numericExpression = /^[0-9]+$/; if(humidity_mm.match(numericExpression) && (humidity_mm>=20 && humidity_mm<=50)){ return true; } else{ alert("Min Temperature value should be Numeric & between 20 to 50!"); document.getElementById("humidity_mm").focus(); return false; } } } </script> Thanks in Advance!! Hello all, I am trying to use document.getElementById in FF but its not working. There is a main page. in that mainpage there is a iframe and in that iframe (id = DocFrame) there is a textbox (id="fileuploadedcnt") which i am trying to access. there is no error. ofcourse i have given name and id to the textbox. Below is the code function ConfirmCertificate(id , Project_ID , Subprogram_ID , ITCType_TI) { frm=document.mainform; //fileuploadedcnt = (document.frames("DocFrame").document.forms("upload_form").elements("fileuploadedcnt").value); filecntobj = (document.getElementsByName("fileuploadedcnt")); filecntobj = (document.getElementById("fileuploadedcnt")); alert(fileuploadedcnt); alert((filecntobj.value)); return; if (fileuploadedcnt>0) { result=confirm("Are you sure you want to confirm this certificate? "); } In the abpve case i tried both the name and id properties. with Name property i get the HTMLObj alert but again it fails if i attach value method. And for id, it doesnt work at all No errors ofcourse in both the cases What am i missing Thanks I need help creating something hard. First I need to divs that change by ONE button and when they change they say two different things and must be onclick. The other thing is there will be 4 buttons. They start black and when you click one it turns grey and when you click another it turns gray and the other one that was last clicked turns back black and same with the other two. I am trying to pass a value to a function autosuggest() f and i but i get the error... Message: Syntax error Line: 21 Char: 29 Code: 0 ajax_autocomplete2/ajax_search_for_airport_framework.js line 21 being q = ..... how do i correctly pass a value to the function and use it in the function to get the value of an element. Code: function autosuggest(f,i) { q = document.getElementById(f).value; .... } 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> Hello, I have a website that I need help with. You can visit it he http://www.shahspace.com/bow/home.html. To see what I need help with, click on the services menu item and observe the alert message that comes up. It should say "point 1". Here is the code that executes that: Code: function enableScrolling(menuName) { alert("point 1"); var menu = document.getElemenetById(menuName); alert("point 2"); ... } As you can see, there should be a second alert message that says "point 2", but there isn't. The script is crash when I try to assign to menu the object returned by document.getElementById(menuName). I have verified that menuName is correct. So why would this be crashing? To get a fuller understanding of my algorithm, I'll give you the following: The menu div: Code: <div id="services_menu" class="services_menu"> ... </div> The "services" button: Code: <td><a href="#" onclick="displayMenu('services'); return false;"><img src="services.jpg" border=0></a></td> The displayMenu() function: Code: function displayMenu(menu) { var menuName = menu + "_menu"; document.getElementById(menuName).style.display = "block"; if (itemCount(menuName) >= 12) { enableScrolling(menuName); } else { disableScrolling(menuName); } } The itemCount() function: Code: function itemCount(menuName) { var menu = document.getElementById(menuName); var divArray = menu.getElementsByTagName("div"); return divArray.length; } And the enableScrolling() function I already posted above. So essentially, when the user clicks on "service", the services menu becomes visible. If the menu contains 12 items or more, scrolling needs to be enabled. This entails setting the menu to a fixed height and allowing the user to scroll through it (scrolling, in this case, will be customized--I'm not using the div's native scrolling feature). The really odd thing is that in itemCount(), I have exactly the same line: var menu = document.getElementById(menuName); and it works fine there. Why not in my enableScrolling() function? http://www.earthinke.co.uk/main_site/product.php Hi I'm trying to get something to work on the site URL'd above but failing miserably. If you can please follow the link, hit the red rectangle on the RHS and then when the bigger image loads into the DIV above, click on it... All I want is for this link to open in fancybox (using the class="earthInke") but it won't work from the image...just opens in a new page Below it you will see a text link, this works as I want it to, but I cannot get it work from the image Probably something completely wrong in what I am doing or I've missed something out, any help would be appreicated guys Thanks Pete In my program there is table which is retrieved and then there radio buttons, after selecting any radio button other columns get exapanded into textboxes to edit info. Now for expansion I have used div<id = > tag for each textbox and In javascript I have a function for showing textbox after clicking a radio button.In that I have used , arr.length=Length of the rows in table function edit1(el) { for(var i=0;i<arr.length;i++) { if(el.value==arr[i].value) { //document.getElementById("test[" + i + "]").value Not workking //document.getElementById('dname['+ i + ']').style.display = block"; Not working document.getElementById('dname').style.display = "block"; document.getElementById('dmarks').style.display = "block"; break; } else { document.getElementById('dname').style.display = "none"; document.getElementById('dmarks').style.display = "none"; } }//end for }//end if } In HTML, while($row1=mysql_fetch_array($rs1)) { echo "<tr>"; /*<td>44:<div id=d4 style="display:none;"><input type=text name=t4 id=idtext></div></td></tr><br>*/ ?> <td><input type="radio" name="select" value="<?php echo $row1['rollNo'];?>" onClick='updateRec(this);'><?php echo $row1['rollNo']; ?> <input type="radio" name="select" value="<?php echo $row1['rollNo'];?>" onClick='hiding(this);'>hide</td> <td><?php echo $row1['name']; ?><div id="dname[]" style="display:none;"><input type=text name="tname[]"></div></td> <td><?php echo $row1['marks']; ?><div id="dmarks[]" style="display:none;"><input type=text name="tmarks[]"></div></td> </tr><br> <?php } // end while ?> </table><br><br> Here I have to take array of div id's = "dname[]" but don't know the syntax for document.getElementById('dname').style.display = "block"; in which dname is array Plz help. Hello again, I seem to be having trouble with my string variable in innerHTML.. here's my code: Code: function header() { // Navigation Bar 110 var o = document.getElementById("header"); 111 var s = '<h3 style="float:left;">' 112 + ' ' 113 + '<a href="http://mattondo.com" class="link">MattOndo.Com</a></h3>' 114 + '<div style="float:right;">' 115 + '<div class="navbar">' 116 + '<a href="index.htm" class="nav" id="home">home</a>' //to homepage 117 + '<a href="about.htm" class="nav" id="about">about</a>' // to about page 118 + '<a href="construction.htm" class="nav" id="blog">blog</a>' // to blog page 119 + '<a href="contact.htm" class="nav" id="contact">contact</a>' // to contact page 120 + '</div>' 121 + '</div>'; 122 o.innerHTML = s; every time I run this using firebug, it says I have one error. That on line 122 variable o is null. And when I go through the code using firebug line by line, it gets to thevar o = document.getElementById("header"); and stores nothing in o, making it null. What could be my issue here?? Hi All, Im trying to get my simple js code to add some code to the html page but cant seem to (i get an error in html page); my JS code: Code: function game() { this.document.getElementById('modalone').innerHTML = "<b style='float: left; text-decoration: underline;'>Deady Teddy</b><img src='css/images/popup/close.png' style='float: right; cursor: hand;' onClick='javascript: hideModal('modalPage');'></img>"; } my html code to call this: Code: <div class="gbox"><img src="css/images/games/dt.gif" /> <a href="javascript: revealModal('modalPage'); game();">Deady Teddy </a> </div> Any Idea's? Thanks In Advance, Jamie. |