JavaScript - Unknown Runtime Error (innerhtml)
So...
I'm using an AJAX query to replace the innerHTML for an element. On the "front end" of the site, this method works fine in IE7/8... For some reason - in the administrative back end - not so much. I'm not sure why. I get an "Unknown runtime error" in IE7/8 - though works fine in Chrome/FireFox... I'm posting the HTML for the page I'm having problems with and also the HTML that is being returned by the AJAX query. I'm beating my head against a wall here. Any help would be great! :-) I've attached the HTML for the page in question... AJAX query returns: Code: <form name="domains" id="domains"> <table border="1" cellpadding="0" cellspacing="0" width="500" id="domain_table"> <tr style="font-weight: bold; font-size: 14px; text-align: center; height: 25px; background: #214232; color: #fff; "><td>Practice Area</td><td>City</td><td>Excellent Keyword Domain Name</td><td>Select</td></tr><tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Bankruptcy</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchorageBankruptcyAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_37" value="37-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Criminal</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchorageCriminalAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_38" value="38-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Divorce</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchorageDivorceAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_39" value="39-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Dui</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchorageDuiAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_40" value="40-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Personal Injury</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchoragePersonalInjuryAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_41" value="41-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> <tr bgcolor="#d6e3bc"><td align="left" colspan="4"><b>Trial</b></td></tr> <tr bgcolor="#d6e3bc"><td> </td><td align="left">Anchorage</td><td align="left">AnchorageTrialAttorney.net</td><td align="center"><input type="checkbox" name="seldomains[]" id="domain_42" value="42-1" /></td></tr> <tr style="background: #fff;"><td colspan="4"> </td></tr> </table> <table border='0' width='500'> <tr><td align='right'><input type=button onClick='addToProduct();' value='Update Product' /></td></tr> </table></form> Similar TutorialsHi, I've written a small script for a website, and strangely enough (or maybe not) it works in Firefox and Chrome but not IE. I'd read about block level inside inline causing this but i'm still not entirely sure. Here is the offending script: Code: function changeImage(image) { if (image == 6) { var vid = document.createElement('object'); vid.width = "700"; vid.height = "370"; vid.id = "photo"; vid.innerHTML = '<param name="movie" value="http://www.youtube-nocookie.com/v/g4cpDgGlFng&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/g4cpDgGlFng&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="700" height="370"></embed>'; document.getElementById("body").replaceChild(vid, document.getElementById("photo")); } else { var img = document.createElement('img'); var old = document.getElementById("photo") img.width = "700"; img.height = "370"; img.id = "photo"; img.alt = "Photo of Gippsland Lakehous"; img.src = "images/photos/" + image + ".jpg"; document.getElementById("body").replaceChild(img, old); } The offending line is the long innerHTML one. I'm sure this must be a very hacky way of doing things (incidentally the thing is replacing an image with another image or video depending on what is clicked), but I rarely code at all, so don't know any better Thanks! I'm getting a runtime error on the code in red. Can anyone see anything that is wrong with it? These functions are called by an onBlur by the way. <script type="text/javascript"> //THIS GENERATES QUANTITY OF MATERIALS function generate3() { var tot3 = document.ComplianceForm.materialamount.value; var tbl3 = document.getElementById("quantitymaterials"); if (tot3 > 28) { alert("16 is total amount of materials for now."); } else { for(var i =1; i<=tot3; i++) { tbl3.innerHTML = tbl3.innerHTML + '<tr><td colspan=\"2\"><hr /></td></tr><tr><td>'+i+') Quantity: <input type=\"text\" name=\"qty'+i+'\" size=\"3\"\/></td><td>Description: <input type=\"text\" name=\"material'+i+'\" /></td></tr><tr><td colspan=\'2\' \">Your Truck<input type=\"checkbox\" \/> Other truck<input type=\"checkbox\" \/> Cash<input type=\"checkbox\" \/> Credit Card<input type=\"checkbox\" \/> P.O.<input type=\"checkbox\" \/></td></tr>'; } tbl3.innerHTML = tbl3.innerHTML + '<br>'; } } function remove3() { var tot3 = document.ComplianceForm.materialamount.value; var tbl3 = document.getElementById("quantitymaterials"); for(var i =1;i<=tot3; i++) { tbl3.innerHTML = ""; document.ComplianceForm.materialamount.value = ""; tbl3.innerHTML = ""; } } </script> I'm pretty new to Javascript so don't lay into me too hard. haha thanks. -Ty I get "Microsoft JScript runtime error: '$' is undefined" with the javascript below. How should I troubleshoot this? <script type="text/javascript" language="javascript"> function ShowPopup() { $('#mask').show(); $('#<%=pnlpopup.ClientID %>').show(); } function HidePopup() { $('#mask').hide(); $('#<%=pnlpopup.ClientID %>').hide(); } $(".btnClose").live('click', function () { HidePopup(); }); </script> What i have is a system where the amount of HTML lines is generated by php when the page loads. Each time has exactly the same set up except there names have an int added to them in accending order. What i need is for them to pass a variable to the javascript function telling them what number they are, and the javascript then using this to access it to read and change information. Is the line below correct for this task? Code: document.Purchase.(Tax+i).selectedIndex; Hi, i have multiple check box and text box for each check box. the check box value is given as text box name ex Checkbox <input type="checkbox" name="cBx" value=" txtname1 "/> Textbox <input type="text" name=" txtname1 " /> how to get the text box value (txtname1) on calling the below function function get_textBox_value() { var c_chkBoxName = ""; var c_txtBoxValue = ""; for (var i=0; i < document.Formname.cBx.length; i++) { if (document.Formname.cBx[i].checked) { c_chkBoxName= document.Formname.cBx[i].value; //working fine... c_txtBoxValue = document.Formname. c_chkBoxName .value; // not working... how to pass the chkbox value for c_txtBoxName } } } Hello. I am setting up a simple registration page for a community arts project, but I am new to JS and having some issues. Right now I have a list of check boxes like this: Code: <input type="checkbox" id="HA0001" onclick="updateTotal()" /> Wendy Day <input type="checkbox" id="HA0002" onclick="updateTotal()" /> Al Benne <input type="checkbox" id="HA0003" onclick="updateTotal()" /> Julie Steppe What I would like to do is GET the input boxes ID value - which will be different for every checkbox. That value will correspond with a variable of the same name in my javascript code, that will be added or subtracted from the users total cost. So when a box is clicked, I need my variable (called "currentId") to update to the ID value, such as "HA0001" - etc. I was thinking something along the lines of this, but I know it is incorrect: Code: var currentId = document.getElementById.id; All the other add/subtract stuff I will figure out, but I am having a problem getting the ID value from a checkbox when it is clicked. Can anyone help me figure this out? THANKS! -AJ an unknown popup appears every once in a while in my site...i have never been using popups ever..and i use wordpress... the popup appears once in every 3 to 7 days ..and sometimes once a every 20 page loads..(my site has lot of impressions so 20 is a high possibility) and the popup link is http://ads.linkbucks.com/redrockspop-sumo.html further i use statcounter (http://www.statcounter.com/) and whos.amung.us (http://whos.amung.us) as visitor tracing systems but i never heard that they cause popups so i guess nothing wrong with that, i tried to find which is the cause of this but i failed.. I appriciate if you guys can help me with this and my site url is : http://channelslk.com Thanks in Advance ok, so I can make an object, I can also make a new instance of that object and have it running around the screen at the same time. What I'm a bit confused about is how to go about things when I want X number of these objects. So instead of making objects seperately I need a loop. Instead of referring to each object seperately every time I want to redraw it, I want to loop through all instances of the object. Except I can't quite see how one goes about doing this. I need something like (pseudocode) Code: for (i = 0;i <= 10; i++) { var dot + i = new Dot; } and var b = numberOfDots; for (i = 0;i <= b; i++) { dot + i +.moveMe(); drawDot(dot + i + .posY, dot + i +.posX); } obviously this code does not work but it represents the essence of what i'm trying to do and can't get my head around, no matter the google searches I try. How would you make a if for a input box =this do this Some if the input boxe value = this then get innerHTMl Can somebody explain me why this isn't working? Code: <SCRIPT TYPE="TEXT/JAVASCRIPT"> // Check lotto var goed = frmTrekking.EersteGetal.value var fout = frmGetallen.Opgegeven_1.value function checkLotto() { if (frmTrekking.EersteGetal.value == frmGetallen.Opgegeven_1.value) { document.getElementById('boldStuff').style.color='#00ff00'; document.getElementById('boldStuff').innerHTML = goed; } else { document.getElementById('boldStuff').style.color='#ff0000'; document.getElementById('boldStuff').innerHTML = fout; } } </script> When I don't use the var, but give for example this: it works ok. Code: document.getElementById('boldStuff').innerHTML = '6'; Does anyone have any suggestions as to how I can get IE working properly with this? It's a, (exempting IE), straight forward line numbering and plain text code view function. When using the line numbering portion, it works fine in Moz based browsers etc, as it does in IE for the initial numbering. On trying to remove the numbers though, (on the second call), IE just seems to cascade the list entries rather than removing them. Code: function process_code(id, number, print) { if (document.getElementById(id)) { var current = document.getElementById(id); var code = current.innerHTML.split('\n'); var count = 0; var xcount = 0; if (number) { if (current.innerHTML.indexOf('<li class="code-entry">') != -1) { code = code.join('\n'); code = code.replace(/\<\/(li\>\<\/ol|li)\>/ig, '\n'); code = code.replace(/\<ol\>\<li[^\>]+\>|\<li[^\>]+\>/ig, ''); current.innerHTML = code.replace(/^\n+|\n+$/g, ''); } else { current.innerHTML = '<ol><li class="code-entry">'+code.join('</li><li class="code-entry">')+'< /li></ol>'; } } else { var doc = window.open('', 'code_print'); var newdoc = doc.document; newdoc.open('text/plain'); newdoc.write(decode_code(code.join('\n'))); newdoc.close(); if (print) { if (navigator.userAgent.indexOf('Opera') != -1) { window.print(); } else { doc.print(); } doc.close(); } } } } Hello, I am a newbie for Javascript. Currently I am doing a website which consists of a lot of contents. Therefore, I hope to get a solution which all my contents are arranged into a table (rows and columns). The condition is that there is only a html page to hold all the contents where there is a "view more" or 'next" button at the bottom and each times user can click to go to the different contents. I have tried to use the innerHTML and I was able to do for 2 pages only...Now I encountered a problem which I need to update more contents to more pages . Can you kindly give some guidelines according to this? Below shows the example code of my website: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="JavaScript" type="text/javascript"> function OpenWindow() { var content=document.getElementById('achieve').rows[0].cells; content[1].innerHTML="<br/><div align='justify' class='style1 style8'><span class='style11'>Another content</span></div>" + "<div align='left' class='style23 style13'>more details</div>"; var content=document.getElementById('achieve').rows[1].cells; content[1].innerHTML=""; var content=document.getElementById('achieve').rows[2].cells; content[1].innerHTML="<strong><em><font class=style13 style23 color=#FF6600><a href='test.html'>back</a></font></em></strong>"; } </script> </head> <body> <!--id starts--> <table id="achieve" width="780" height="387" border="0"> <tr> <td width="10" height="39"> </td> <td width="340"><div align="center" class="style6">My Title</div></td> <td width="416"> </td> </tr> <tr> <td> </td> <td><div align="justify" class="style1 style8"><span class="style11">More Contents here</span></div></td> <td> </td> </tr> <tr> <td> </td> <td><div align="right"><strong><em><font class="style23 style13" color="#FF6600"><a href="#" onclick="OpenWindow()">+ view more </a></font></em></strong></div></td> <td> </td> </tr> </table> </body> </html> Hey, for some reason, this isn't working because of the src="images/edit.png" attribute. Here is my code: Code: <a href="#" onclick="change('HEYYY')"><img src="images/edit.png" alt="Edit" id="edit1" /></a> Javascript (External) Code: function change(message) { document.getElementById('edit1').innerHTML = '<input type="text" value="'+message+'" />'; } It does nothing. But if I take the src attribute out, it works fine. Any help? Thanks. Hello. I have created a form via innerhtml, like this: content.innerhtml = "<form action =\"customer.php\" method=\"post\">"; content.innerhtml = "<input type = \"text\" name = \"Username\" />"; content.innerhtml = "<input type = \"submit\" value = \"Submit\" />"; When I click submit, instead of running the php file, nothing happens. I tested it outside the script and it works just fine. Is there any other way I can make this work inside the script? Thank you. I'm working on a script that inserts things into tables. It's complicated and involves xmlhttp and lots of stuff, but I've narrowed the problem down to something simple. The following code does not work in IE. It doesn't generate an error, but simply displays nothing. Here is the code: Code: <body> <table id="test"> </table> <script type="text/javascript"> document.getElementById('test').innerHTML = '<tr><td>test<\/td><\/tr>'; </script> </body> I have no idea why it isn't working as it works in Safari and Firefox. Help is much appreciated. Julian Hello. I'm trying to change the text on my page dynamically using getElementById etc. Just not quite sure how to do it. Code: <script> function changeIt() { document.getElementById('change').innerHTML = '*i want the stuff below here (from 'var' to 'text')*'; } var Result= ((correct / 5) * 100) + '%'; document.write('<p>Result<b>' + score + '</b></p>'); document.write('<p>some text</p>'); </script> // <div id = "change"> *all the info I'm going to replace* </div> Just need to know how to put the variables and stuff in the 'innerhtml' part? Thanks. Hello. I have the following: bottomCell.innerHTML = "apples 0"; bottomCell.innerHTML.replace("apples", "oranges", "gi"); The first line works fine, the second one doesn't. In the end, I want it to replace all instances of the numerical variable named myNumber to the string "t" + newNumber (where newNumber is another numerical variable) but neither this, nor the above mentioned line work. Any ideas? Thanks! Hi there, Ive check the following code in all major browser and it works fine accept ofcourse in IE. Im trying to take the innerHTML from one row and move it to the one above or below depand on the button you are clicking. Does anyone have any idea? Many thanks mkariti <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <style type="text/css"> TABLE { border-collapse: collapse; } TBODY { border-top: solid black 1px; } TR { border-bottom: solid black 1px; } </style> <script type="text/javascript" language="javascript"> var getId; var row = { selected: -1, hoverColor: '#CCCCCC', defaultColor: '#FFFFFF', onclick: function (trow, id) { getId = id; var r = document.getElementById('row_' + row.selected); if (row.selected != -1 && r) r.bgColor = row.defaultColor; row.selected = id; trow.bgColor = row.hoverColor; }, test: function (num) { var table = document.getElementById("tableId"); var getRowLength = document.getElementById("tableId").rows.length; if (num == 1) { // table.rows[getId].parentNode.insertBefore(table.rows[getId], table.rows[getId - 1]); // getId++; var tempDown = document.getElementById("row_" + getId).innerHTML; document.getElementById("row_" + getId).innerHTML = document.getElementById("row_" + (getId + 1)).innerHTML; document.getElementById("row_" + getId).bgColor = row.defaultColor; document.getElementById("row_" + (getId + 1)).innerHTML = tempDown; document.getElementById("row_" + (getId + 1)).bgColor = row.hoverColor; getId++; } else { // getId--; // table.rows[getId].parentNode.insertBefore(table.rows[getId + 1], table.rows[getId]); var tempUp = document.getElementById("row_" + getId).innerHTML; document.getElementById("row_" + getId).innerHTML = document.getElementById("row_" + (getId - 1)).innerHTML; document.getElementById("row_" + getId).bgColor = row.defaultColor; document.getElementById("row_" + (getId - 1)).innerHTML = tempUp; document.getElementById("row_" + (getId - 1)).bgColor = row.hoverColor; getId--; } } } </script> </head> <body> <div> <table id="tableId"> <tbody> <tr id="row_1" onclick="row.onclick(this,1);"><td><input type="checkbox"></td><td>Row 1</td><td>A</td></tr> <tr id="row_2" onclick="row.onclick(this,2);"><td><input type="checkbox"></td><td>Row 2</td><td>B</td></tr> <tr id="row_3" onclick="row.onclick(this,3);"><td><input type="checkbox"></td><td>Row 3</td><td>C</td></tr> <tr id="row_4" onclick="row.onclick(this,4);"><td><input type="checkbox"></td><td>Row 4</td><td>D</td></tr> <tr id="row_5" onclick="row.onclick(this,5);"><td><input type="checkbox"></td><td>Row 5</td><td>E</td></tr> </tbody> </table> </div> <div> <button id="btn_down" onclick="row.test(1)">Down</button> <button id="btn_up" onclick="row.test(2)">Up</button> </div> </body> </html> |