Click to See Complete Forum and Search --> : "unknown runtime error" writing innerHTML
russ_man7
02-18-2003, 02:00 PM
I want to write the value of a textbox into the innerHTML of a script tag. the DOM path and all is fine, the script recognizes the new script tag and its innerHTML property and everything, but when i try to write to it, i get an "unknown runtime error". here's a watered down version of what i've got now:
<script> //main script
function workIt()
{
window.caller.innerHTML = phone.value;
}
</script>
<script id="caller"></script> <!--where i want to write to-->
<form onSubmit="workIt()">
<textarea id=phone></textarea>
</form>
this is exclusively for IE5.0+, i'm using it as my active desktop
khalidali63
02-18-2003, 02:32 PM
script tag does not have id attribute.
You are trying to reference an id just by its name which may work in <IE6 but since IE6=> is more standard compliant then the previous versions I am sure at some point just referecning an id by its name will not work.
being safe side is writing better code.
Form elements hould have names in this case.
<form onSubmit="workIt()">
<textarea name=phone></textarea>
</form>
and then access the value like this
document.getElementById("itemID").innerHTML = document.formName.elementName.value
Hope it made sense
Cheers
Khalid
russ_man7
02-18-2003, 03:11 PM
nope, it didn't recognize the document.getElementById("caller").innerHTML at all. it seemed ok with window. i'm testing the properties with an if-else statement:
if (document.getElementById("caller").innerHTML)
{
alert(document.getElementById("caller").innerHTML);
}
else
{
alert("no document.getElementById("caller").innerHTML");
}
it gives me the 'else' alert with getElementById, but it accepted window.caller.innerHTML, and read it back to me when i used that. it just gives me the unknown runtime error, with both methods. i'd be grateful for any more ideas, though. i'm in no rush to finish, it's more of an ongoing project. thanks
Russell
Dan Drillich
02-18-2003, 08:33 PM
Please try -
<script>
function workIt() {
var eId = "1";
if (document.getElementById(eId) != null && document.getElementById(eId).innerHTML != "")
{
alert('no document.getElementById('+eId+').innerHTML');
}
else
{
alert('no document.getElementById(eId).innerHTML');
}
}
</script>
<form onSubmit="workIt()">
<textarea id="1" name=phone>aaaa</textarea>
<input type="submit">
</form>
russ_man7
02-18-2003, 09:48 PM
Thanks, but that wasn't quite what i had in mind. this does a nice job of putting a textarea value in an alert, but i'm trying to stick the value of the textarea into a "function tempFunction{ " + textarea.value + " }" kind of string, then write that to another script tag innerHTML, so i can write and call a function from within the webpage. i'm fine with making the function string and then calling the new function and all, but i'm stuck writing to the innerHTML of the script tag. Any help would be much appreciated.
dreaken667
12-06-2007, 01:42 AM
The script tag doesn't have an innerHTML attribute to write to. Try using something like this:
<script>/* tag to write to */</script>
<script>
str = "function test(){ alert('this is a test'); }";
// you can locate the script tag however you like,
// but use .text instead of .innerHTML
document.getElementsByTagName("script")[0].text = str;
test();
</script>