View Full Version : [JS] getElementById & <script> tags
themoose
June 24th, 2008, 18:15
Anybody have any idea how to do this sort of thing in javascript?
//SCRIPT
document.getElementById('testing').innerHTML='<script type="text/javascript">
<!--
extra variables and code
// -->
</script><script type="text/javascript" src="http://www....../script2.js"></script>';
document.getElementById('testing_text').value='<script type="text/javascript">
<!--
extra variables and code
// -->
</script><script type="text/javascript" src="http://www....../script2.js"></script>';
//HTML
<div id="testing">
<script type="text/javascript" src="http://www....../script.js"></script>
</div>
<textarea id="testing_text">
<script type="text/javascript" src="http://www....../script.js"></script>
</textarea>
Been messing around for ages trying all sorts... it doesn't seem to want to work.
Dynash
June 24th, 2008, 18:21
You want to run JS in a certain div?
<div id="this">
<script type="JavaScript">
code here
</script></div>
I'm not understanding what you're trying to do though :/
iBrightDev
June 25th, 2008, 00:27
are you trying to do something like this Colin?
http://mct-hosting.com/textToInput.php
krakjoe
June 25th, 2008, 05:10
<textarea id="theTextArea" rows="10" cols="20"></textarea>
<script>
window.onload=function()
{
document.getElementById('theTextArea').value = '<' + 'script language="javascript"'+ '>' +
'alert("Hello World")'+
'<\/script>';
}
</script>
themoose
June 25th, 2008, 11:10
You want to run JS in a certain div?
<div id="this">
<script type="JavaScript">
code here
</script></div>
I'm not understanding what you're trying to do though :/
I want to write that javascript to a div using javascript
are you trying to do something like this Colin?
http://mct-hosting.com/textToInput.php
Not quite..
<textarea id="theTextArea" rows="10" cols="20"></textarea>
<script>
window.onload=function()
{
document.getElementById('theTextArea').value = '<' + 'script language="javascript"'+ '>' +
'alert("Hello World")'+
'<\/script>';
}
</script>
Cheers man I'll give it a go
themoose
June 25th, 2008, 11:15
<textarea id="theTextArea" rows="10" cols="20"></textarea>
<script>
window.onload=function()
{
document.getElementById('theTextArea').value = '<' + 'script language="javascript"'+ '>' +
'alert("Hello World")'+
'<\/script>';
}
</script>
Okay, that works well, but I also need to write specific vars to the textarea. such as:
<script type="text/javascript">
<!--
english = "hello";
german = "Guten Tag";
// -->
</script><script type="text/javascript" src="http://www....../script2.js"></script>
Still can't get it.
doof92
June 25th, 2008, 11:40
Hope you don't mind me posting a similar question here (will delete if you rather keep it to your own topic).
I want to do something similar, but add an additional parameter to the <body> tag using Javascript. As part of a Greasemonkey script, I want to add an onload function. How would I go about this?
Thanks
iBrightDev
June 25th, 2008, 11:51
Hope you don't mind me posting a similar question here (will delete if you rather keep it to your own topic).
I want to do something similar, but add an additional parameter to the <body> tag using Javascript. As part of a Greasemonkey script, I want to add an onload function. How would I go about this?
Thanks
<body onload="function">
doof92
June 25th, 2008, 12:38
Yeah, but I want to add the onload bit using javascript.
iBrightDev
June 25th, 2008, 13:14
explain more. need more details
doof92
June 25th, 2008, 13:30
Moved to my own thread. Sorry to Mentok.
themoose
June 25th, 2008, 14:22
No problem.
Blergh, RE my problem, forget it for now.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.