/    Sign up×
Community /Pin to ProfileBookmark

IE -> Not Working simple function that works in firefox

hey!

Anyone knows why this code works in firefox but not in IE

document.getElementById(‘hiddencontent’).innerHTML = document.getElementById(‘globalcontent’).innerHTML;

It is a function to copy all the contents from a div to a textarea, it works fine in firefox, buy i need it to work in IE too.

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@keithnormJul 25.2008 — try value of textarea instead of innerHTML
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — try value of textarea instead of innerHTML[/quote]

unknown runtime error
Copy linkTweet thisAlerts:
@rnd_meJul 25.2008 — unknown runtime error[/QUOTE]


[CODE]
document.getElementById('hiddencontent').value= document.getElementById('globalcontent').innerHTML;
[/CODE]

doesn't work?

which one is textarea?
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — <i>
</i>document.getElementById('hiddencontent').value= document.getElementById('globalcontent').innerHTML;
doesn't work?

which one is textarea?[/quote]


I had to make a hack:

if(navigator.appName != "Microsoft Internet Explorer")
{
document.getElementById('hiddencontent').innerHTML = document.getElementById('globalcontent').innerHTML;

}
else
{
document.getElementById('hiddencontent').value = document.getElementById('globalcontent').innerHTML;

}


hiddencontent is the textarea, I don't like hacks if you know any other method i will thank u
Copy linkTweet thisAlerts:
@FrankTheTankJul 25.2008 — How is your script tag's type attribute set? I learned the [B]HARD[/B] way that it needs to be set to text/javascript, NOT application/javascript. I use Dreamweaver for most of my coding, and guess what it suggests higher up on the list? It's alphabetical. ? Also, FF is OK with application/javascript, but IE will ignore it. Be sure it's set to text/javascript, every time. I'll never get that piece of my life back, but maybe you can avoid losing it.

Frank
Copy linkTweet thisAlerts:
@felgallJul 25.2008 — application/javascript is the standard value which ought to be used except for the fact that IE doesn't support it.

text/javascript is deprecated but is the only value that works for all browsers.


How are the hiddencontent and globalcontent fields defined in the HTML?
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — I used:

language="javascript" src="ajaxsubmit.js" type="text/javascript"

Always use this method.
Copy linkTweet thisAlerts:
@HoboScriptJul 25.2008 — EDIT: Wait a minute here. It's a text area and you were putting in innerHTML.... hmmmmm...


This code works in IE.
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script language="javascript" type="text/javascript"&gt;

window.onload = function() {
document.getElementById("test").appendChild(document.createTextNode("Test"));
}

&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;textarea id="test" style="width: 50px; height: 100px;"&gt;&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — Look:

globalcontent is a Div tag <div id="globalcontent">BLABLABLA</div>

hiddencontent is a textarea <textarea id="hiddencontent" name="content" rows="40" cols="70" ></textarea>

I have basically an ajax aplication that updates some html inside the globalcontent and afther updates a textarea with the contents of the div


here is the ajax:


[CODE]
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;

try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {

try{

xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}

return xmlhttp;
}

function edittemplate() {
var divid = escape(encodeURI(document.getElementById("field2").value ));
var productid = escape(encodeURI(document.getElementById("field1").value ));
var strURL = "ajaxfunct.php?action=edittemplate&productid="+productid+"&type="+divid;
var req = getXMLHTTP();
if (req) {

req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById(divid).innerHTML=req.responseText;
if(navigator.appName != "Microsoft Internet Explorer")
{
[COLOR=Red] document.getElementById('hiddencontent').innerHTML = document.getElementById('globalcontent').innerHTML;[/COLOR]
}
else
{
[COLOR=Red]document.getElementById('hiddencontent').value = document.getElementById('globalcontent').innerHTML;[/COLOR]
}
} else {
alert("There was a problem while using XMLHTTP:n" + req.statusText);
}
}

}

req.open("GET", strURL, true);
req.send(null);
}
}

[/CODE]


It basically has two dropdowns and afther submit the form the php function takes the vars sent and sends an output, that's done actually very well, afther the

document.getElementById(divid).innerHTML=req.responseText;

it has to update a textarea this way i have a new content updated for sending to database

[COLOR=Red]document.getElementById('hiddencontent').value = document.getElementById('globalcontent').innerHTML;



[COLOR=Black]this code copies the globalcontent html and pastes into hiddencontent textarea, this method works fine firefox but not in IE, the code is in an external file linked this way:



<script language="javascript" src="ajaxsubmit.js" type="text/javascript"></script>



[/COLOR]
[/COLOR]
Copy linkTweet thisAlerts:
@HoboScriptJul 25.2008 — Read the post I made above. I gave you a code solution that works.
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — Read the post I made above. I gave you a code solution that works.[/quote]

I don't need it to be window.onload, since it has to be updated every ajax change and you know ajax don't reload page
Copy linkTweet thisAlerts:
@HoboScriptJul 25.2008 — I don't need it to be window.onload, since it has to be updated every ajax change and you know ajax don't reload page[/QUOTE]

*sigh* the fix wasn't onload, try this:

document.getElementById("test").appendChild(document.createTextNode("Test"));
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — I think this would put the "Text " node inside the textarea ain't it?
Copy linkTweet thisAlerts:
@HoboScriptJul 25.2008 — I think this would put the "Text " node inside the textarea ain't it?[/QUOTE]

Is that not what you want?
Copy linkTweet thisAlerts:
@elpaisaauthorJul 25.2008 — NO i just want to copy the contents of a div inside a textarea
Copy linkTweet thisAlerts:
@HoboScriptJul 25.2008 — Okay lemme explain something here. I'll even put it in steps.

  • 1. Grab reference to text area.

  • 2. Grab reference to div.

  • 3. Create variable and set div content to it as a string.

  • 4. Set textarea content with the variable above.

  • 5. Tada.


  • What you are asking is exactly what I just aimed to provide. Once you grab the innerHTML of the div. You can set the textarea with the createTextNode(divDataOrWhatever)
    Copy linkTweet thisAlerts:
    @elpaisaauthorJul 25.2008 — let me test then
    ×

    Success!

    Help @elpaisa spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...