InnerHTML And <script>

Jul 6, 2006

I want to load an external file into my page via XMLhttpRequest and
innerHTML. The external file contains javascript code which is not executed during
or after insertion. All the HTML markup is displayed just fine....
basicly even this code doesnt work:

<div id='tmp'>original Content</div>

<script>
document.getElementById("tmp").innerHTML="<b>new</b>
Content<script>alert('not shown! why?');</script>";
</script>

looking at the page, "new Content" is shown with "new" bold as
expected, but there wont be the javascript alert!

View 1 Replies


ADVERTISEMENT

Any Way To Add If And Else Within InnerHTML

Mar 16, 2009

Is there a way to add an if and else with in innerHTML like this.
var sfe = document.getElementById("mainform").innerHTML ='<form name="'+frmName+'">'+
'<!-- comment -->'+
'<h2 id="pa" name="dr">';if(n == 1){'+fname+'}else if(n == 2){<b>No Title</b>} '</h2>'+
'more'+

View 4 Replies View Related

Using DOM Instead Of InnerHTML

Apr 10, 2006

I'm currently using AJAX to perform some dynamic updates and return some text to the web page. At the moment I'm using innerHTML as follows:

document.getElementById('WrkItemDiv').innerHTML=wrkItemReq.responseText;

but I'd like to be standards compliant. How would I do this using pure DOM stuff?

btw WrkItemDiv is an exisiting <div> I simply want to overwrite the text within it with the newly returned text.

Also, is it possible to change the onMouseOVer code with some text returned in the same way as above using pure DOM?

View 12 Replies View Related

InnerHTML

Oct 22, 2007

I am getting data from two tables in a database using a dropdown box with a onchange and some ajax to update two diferent Div tags, basically the id is passed to a php page,, I grab the data from the two tables, I then echo the data in two html tables. I echo a ** for a delimiter between the two tables,

Then I use a javascript split function to split the responseText into two peices so I can update each DIV with the coresponding data.

Everything works in Firefox, but in IE7 only one div gets updated with its data, the other div will not change, and I get a unknown runtime error. However if I go into my php page and change the data I am echoing after the delimiter to a simple echo 'test' it will work. Code:

View 2 Replies View Related

DOM Row/cell With InnerHTML

Jul 23, 2005

I've got this code that creates a new new row and cell. I then put some
text into the cell with innerHTML - works beautifully with Firefox but
fails with IE. I guess IE doesn't support this way of doing it, but is
there another way of doing it with DOM?

newr = document.createElement('tr');

stbl.appendChild(newr);
newc = document.createElement('td');

newr.appendChild(newc);
newr.cells[0].innerHTML = (nr+1)+". "+sa[ti][nr + 1]+"<br><hr>";
(works in firefox but fails in IE 6+ too...)

View 22 Replies View Related

InnerHTML In IE Vs Firefox

Jul 23, 2005

Here is my problem in a nutshell: a script to model dynamic table
extension. It works under Firefox. But IE just aborts, complaining about
an "unknown runtime error" in the line with "innerHTML". Why?

<html><head></head><body>

<script language="javascript">
function extend() {
var tb = document.getElementById('thetable').tBodies[0];
var newrow = document.createElement('tr');
tb.insertBefore(newrow,tb.rows[tb.rows.length-1]);
tb.rows[tb.rows.length-2].innerHTML =
'<td>A</td><td>dummy</td><td>row</td>'
}
</script>

<table id="thetable">
<tr><td>1-1</td><td>1-2</td><td>1-3</td></tr>
<tr><td>2-1</td><td>2-2</td><td>2-3</td></tr>
<tr><td>3-1</td><td>3-2</td><td>3-3</td></tr>
<tr><td colspan="3"><a href="javascript:extend();">extend</a></td></tr>
</table>
</body>
</html>

View 1 Replies View Related

IE Munges InnerHTML

Jul 23, 2005

IE seems to munge the innerHTML of a document, does anyone know why
it's changing the innerHTML?

<body>

<div style="background-color:LightGrey;" onclick="window.alert( 'one:'
+ getElementById('one').innerHTML );" id="one">
<table id="tableone">
<tr id="trone">
<td>click me</td>
</tr>
</table>

</div>

<div id="two" style="background-color:LightBlue;"
onclick="window.alert( 'two:' + getElementById('two').innerHTML );">
<table id="tabletwo">
<tr id="trtwo">
<td>click me too</td>
</tr>
</table>
<input type="checkbox" checked="checked" value="MYVAL" />
</div>
</body>

View 4 Replies View Related

Firefox And InnerHTML

Jul 23, 2005

Why doesn't a SELECT element's innerHTML reflected which option was
selected? Works in IE. I need this functionality so that I can retain
what choices a user made in a tabbed interface.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://w3.org/1999/xhtml">
<head>

<script language="javascript">
function callAlert(){
var theHTML = document.getElementById('Radius').innerHTML;
//alert(theHTML);
}
</script>
<title>Untitled Document</title>
</head>

<body>
<form id="myForm">
<div id="myDiv">
<table border="0" width="430" cellpadding="3" cellspacing="0">
<tr>
<td font color="#ff0000">*</font>Radius:</td>
<td width="331" height="30" class="formData">
<select onChange="callAlert();" id="Radius" name="Radius">
<option value=".10" id="0">1/10 mile</option>
<option value=".20">1/5 mile</option>
<option value=".25">1/4 mile</option>
<option value=".5">1/2 mile</option>
<option value=".75">3/4 mile</option>
<option value="1">1 mile</option>
</select>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

View 24 Replies View Related

Using Frames And Getting InnerHTML

Mar 8, 2006

I am using a frameset with two frames that looks like this:

|------------------------------|
| |--------------------------| |
| | FRAME 1 | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| |--------------------------| |
| |
| |--------------------------| |
| | FRAME 2 | |
| | | |
| | <html><body> | |
| | <table><tbody> | |
| | <tr> | |
| | <td>Data 1</td> | |
| | <td>Data 2</td> | |
| | </tr> | |
| | </tbody></table> | |
| | </body></html> | |
| |--------------------------| |
|------------------------------|

FRAME 2 has no height, so it looks as if you only have 1 frame. I am
using FRAME 2 to retrieve data from my server.

I open up FRAME 1 with my webpage and leave FRAME 2 empty. When the
user request data I target FRAME 2 and the data is loaded into FRAME 2.

What I have been trying to do is this. Take the innerHTML of the FRAME
2's table and load it into a table in FRAME 1.

View 1 Replies View Related

InnerHTML And SCRIPT Tag

Jul 19, 2006

I use Ajax to retrieve part of a page I need to update. I update a DIV
element with the HTML contents I get from another page.

It works fine.

However the HTML have a SCRIPT tag that the browser should process, but
it doesn't.

Here's an example:

--- pageX.aspx ---
<table>
<tr>
<td>Table 01</td>
</tr>
</table>
<script>
alert("HI");
</script>
--- end pageX.aspx ---

--- page on browser ---
<div id="divContents"></div>

<script>
divContents.innerHTML = getHtmlFromPage("pageX.aspx");
</script>
--- end page on browser ---

When the prowser gets the "pageX.aspx" and updates the contents of the
'divContents' it displays the table, but it didn't process the script.

What am I doing wrong?

View 17 Replies View Related

A Debugger To Let Me See The InnerHTML Of A Div?

Sep 29, 2006

What debugger would let me see the HTML in a div after I've added HTML
to the div using its innerHTML? That is:

var someInputHtml = prompt("input html");
var referenceToSomeDiv = document.getElementById("someDiv");
referenceToSomeDiv.innerHTML = someInputHtml;

When debugging, how do I now see what HTML is in the div "someDiv"?

Maybe there is a FireFox extension for this? Firebug?

View 5 Replies View Related

Why I Can't Use AttachEvent With InnerHTML;

Apr 27, 2007

if i use AttachEvent like this,it can't work;
eg:

var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";

but i use attachEvent like this,it work; eg:

var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var text = document.createElement("span");
text.innerHTML="<-click this";
var div = documet.createElement("div");

div.appendChild(img); //can work
div.appendChild(text);

View 6 Replies View Related

Var.innerHTML Where Var Is A Variable!!

Jul 20, 2005

Is there any way to use a variable.innerHTML = ""; instead of text.innerHTML
= "";? It doesn't seem to work for me.

View 2 Replies View Related

Javascript InnerHTML

Jul 20, 2005

How can I get the innerHTML of a <div> area only when the page loads, then use that variable in a function?

Here is my code:
function setContent(zz)
{
var lb = document.getElementById('leftbar').innerHTML;
var rb = document.getElementById('rightbar').innerHTML;
document.getElementById("myContent").innerHTML = "<span class="title_Page">"+Page[zz]+"</span>";
if (zz=="home") {
document.getElementById('leftbar').innerHTML = lb;
document.getElementById('rightbar').innerHTML = rb;
document.getElementById('leftbar').style.width = &#39135;px'
document.getElementById('rightbar').style.width = &#39135;px'
}
else {
document.getElementById('leftbar').innerHTML = "";
document.getElementById('rightbar').innerHTML = "";
document.getElementById('leftbar').style.width = &#390;px'
document.getElementById('rightbar').style.width = &#390;px'
}
}

I want lb and rb to be set only once (i.e. only when the page loads the first time). I tried putting those variables outside the function, but when I do they, they show up as undefined. So how could i code it so that when the page loads, it assigns the innerHTML to the two variables, but not any other time while that page is open?

View -1 Replies View Related

InnerHTML Of Another Frame

Jul 20, 2005

I have a page as follows:

<HTML>
<FRAMESET ROWS="20%, 80%">
<FRAME SRC="editor.html" NAME="editor">
<FRAME SRC="testfile.html" NAME="reader">
</FRAMESET>
</HTML>

editor.html contains the following code:

code = document.documentElement.innerHTML

which gives me the HTML-code of editor.html as expected.
Now I want to read the HTML-code of testfile.html instead. But

code = parent.reader.document.documentElement.innerHTML

just returns

<head></head><body></body>

with Mozilla, and IE gives an error.

Can somebody explain why this happens, and how I can solve it?
Since the first case works on all browsers I tried, I was hoping to get
a browser-independant method to read the sourcecode of another file.
By the way, all files are local.

View 1 Replies View Related

Iframe InnerHTML

Jul 20, 2005

I'm using an i-frame to grab a server-side text file and display its content
elsewhere in the html document. On change of the i-frame source, I want to
access its innerHTML.

The i-frame source changes just fine and even displays the source; the glitch
is in accessing the innerHTML for that new i-frame src file. It requires *TWO*
clicks of the onClick element to get the correct innerHTML (with just one
click, the source will change, and display the new file in the html document;
however, the innerHTML is still that of the old source file for the i-frame).

This does not appear to be a loading problem with the new src file into the
i-frame. (ie: setTimeout on a function to get the innerHTML after the src file
loads does not work).

So the question is: how can I get the i-frame source to change AND access the
new src file's innerHTML with one click?? Code:

View 4 Replies View Related

Put PHP Loop On A InnerHTML?

Aug 30, 2011

so I have this code for a date form and I made a PHP loop and even a javascript loop for it. There is a script that supposedly adds multiple 'dates' when the user clicks this 'add more date' button and I use an innerHTML to clone it.

My problem is how will I put it inside an innerHTML on a javascript. Since innerHTML reads html tags, is it possible to put a PHP loop within it? and how will you also call a javascript function within it?

this is the PHP code:
<select>
<?php
for ($i=date("Y"); $i>=1950; $i--)

[Code]....

I just need to know if what im doing is right, or is there another way to do this?

View 4 Replies View Related

InnerHTML Not Displaying In IE

Apr 14, 2009

I have innerhtml loading at the end of a table run function in FF it works, in IE it does not. I have tbody and all other necessary elements.

View 1 Replies View Related

InnerHTML In IE With Tables?

Nov 21, 2009

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:

<body>
<table id="test">
</table>

[code]....

View 3 Replies View Related

InnerHTML - Hide TR If TD Within It

Feb 25, 2010

I'm trying to hide a TR if a TD within it has only specific html in it. Why would this not work:
if(document.getElementById('website1').innerHTML.toLowerCase()=="<a href='' title=''></a>")
{
document.getElementById('website-row').style.display='none';
}

View 4 Replies View Related

InnerHTML Onmouseover!

Apr 3, 2007

I tried this script and doesn't seem to work!

<span onmouseover="innerHTML:'. . . . . . . . . . . . . '" onmouseout="innerHTML:'. . . . . . . . . . . . . . . . . . . . . . '">. . . . . . . . . . . <br />. . . . . </span>

Any ideas?

View 3 Replies View Related

InnerHTML Property

Apr 9, 2007

I'm using javascript to dynamically make controls show up or disappear on a form. For some reason, if I load a control (in this case a select control) into the Div it shows up perfectly. If I load text in there, it is fine too. However, if I programmatically try to go from the select control content and cover it with text afterwards, that won't work.

If I change the content from one string to another, it works as well. I just cannot remove a control I've put down and replace it with text or "" or whatever.

View 1 Replies View Related

Getting Innerhtml Of Iframe

Feb 7, 2008

I am nOOb to Javascript and wanted to extract HTML from another website. I tried this by using an iframe that opened up the desired webpage and called a script to read the innerhtml of the frame using the onLoad event.

It fails however with a Permission Denied error when trying to extract the html via the script (see code below).

Not sure if I am doing something worng, or if this is just not allowed on ClientSide scripting (I can appreciate writing isn't) but not being able to read.

Anyway, assuming this can't be done in this manner, is there another way in which it might short of using server side scripting?

<SCRIPT language = "Javascript">
function readFile()
{
doc=window["myframe"].document.body.innerHTML;
//TBD...

}
</SCRIPT>

View 2 Replies View Related

InnerHTML Placement

Mar 5, 2006

I have recently decided to re-approach a function in the code I have been working on based on the recommendations of a few of you helpful folks. The current function takes data accumulated from form calculatiions, formats it for display then opens a fresh window and writes that data into the document using the document.write() method. This presented me with a bit of a problem when it came to saving the document, particularly in Internet Explorer. When I brought that problem up here on the boards, it was suggested that I go from document.write() to innerHTML and rather than open a blank document, I should open a document that at least has the basic coding set up, such as DOCTYPE, HEAD and BODY tags.

This is all fine and dandy and I understand the basic concepts of how it is supposed to work, but in working through the logic of the process, I discovered that my weakness in understanding how to implement the innerHTML method is holding me back a bit. So now I come seeking advice once more, however, before I go any further with this, let me explain how the document is meant to be displayed.

The data is sent to the document in two basic stages. The first of those stages is a visual or "graphical" representation of the data and consists of a foundation image (in this case, a polar chart) with secondary images (stellar bodies and/or stars) placed on top of it to represent the data in a positional format (basicly stars positioned by Right Accension and Declination Angle).

The second stage of the data transfer (which, at this point, I don't see any problem coding since it is pretty straight forward) is a text rendering of the processed information in a tabular format. For the most part, I intend to keep it in tabular format and simply send it to a specific DIV element.

My difficulties are coming from the first stage of the process. My first thought was to load the foundation image from the popup itself rather than using the function to insert it in the document and then send the positioning data to the document as a series of DIV elements in much the same fashion as I was doing before. These DIV elements, or so I assume, when sent to the document, would have to be placed in the body of the document in general. Therefore, I would assume that the body would have to have a name/id attribute that innerHTML could access. My question here is, where exactly does that data go when it is sent. Assuming the basic document has the following appearance; Code:

View 9 Replies View Related

IE Doesnt Like .innerHTML?

Mar 23, 2006

ive got a problem with some of my code. mozilla likes it, but IE gives an error and doesnt do anything with the code what im trying to do is show two fields only if a checkbox is checked. the javascript function is as follows:

function change_permission(){
if(document.category.permission.checked){
document.getElementById('login').innerHTML='<td colspan="2"></td>'
document.getElementById('password').innerHTML='<td colspan="2"></td>'
}else{
document.getElementById('login').innerHTML='<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Login: </font></div></td><td><input type="text" name="login" value="{$login}"></td>'
document.getElementById('password').innerHTML='<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password: </font></div></td><td><input type="password" name="password" value=""></td>'
}}

the fields in the form, with default value:

<tr id="login"><td colspan="2"></td></tr>
<tr id="password"><td colspan="2"></td></tr>

View 2 Replies View Related

InnerHTML Vs Standards

Oct 27, 2006

The DOM methods have the usual pros of being supported and part of the standard, so in an ideal world should be forward compatible and work within all browsers. But we know this isnt always the case.

The opposite seems the be true for innerHTML. It is not standards based and as people keep mentioning could be removed at any time (though this is highly unlikely)

The advantages I see innerHTML having is that it is widely supported (maybe even more so than the DOM methods) and in tests always runs faster.

I'm still in 2 minds over which to use. I find myself using innerHTML for adding large or complex amounts to the DOM and the DOM methods for everything else.

How do you approach it? When do you use innerHTML/DOM and under what circumstances would you contemplate changing the method you use? In your opinion which is the best method?

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved