Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: open

Message Too Old, No Replies

onload javascript -- writes textbox content into a frame

only works when I precede it with an alert()

     
10:20 am on Mar 7, 2003 (gmt 0)

New User

10+ Year Member

joined:June 16, 2002
posts:13
votes: 0


This may be very simple but just could not find the solution:
I have a function called initEditor that runs on pageload that should get the value of as textbox and write it into a frame, the function looks like this:

function initEditor(){
document.frames('myEditor').tbContentElement.DOM.body.innerHTML = document.frmInsert.txtBody.value;
}

Somehow this does not work, but when I add an alert function before, then it works:

function initEditor(){
alert()
document.frames('myEditor').tbContentElement.DOM.body.innerHTML = document.frmInsert.txtBody.value;
}

Can anybody explain this to me?

thanx

Pete

3:29 pm on Mar 7, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts:364
votes: 0


i suggest you completely move over to document.getElementByID("elementID")
or
document.getElementByName("elementName")

and as long as those elements you are interested in have id's and/or names, you can use them. for example (im not 100% this is right)

for instance, this is how your tags might look, whereever they are:

<input type='text' id='grabThisText'>
<frame name='leftFrame'>

and in your onload function, this would be it,

document.getElementByName("leftFrame").innerHTML = document.getElementByID("grabThisText").value

now one thing: i am not going to lie to you: i never use javascript for forms, so that last part could be wrong...

4:50 pm on Mar 7, 2003 (gmt 0)

New User

10+ Year Member

joined:June 16, 2002
posts:13
votes: 0


hi sethcall,

sorry but this didn't solve it I still get the same behavior. Only when I add an alertbox it writes the content of the textbox into the frame.

4:53 pm on Mar 7, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 9, 2002
posts:325
votes: 0


Hi Pete,

It could be that your JavaScript is trying to write content before the IFrame has been set up correctly.

Putting the Alert box before the copy makes the JavaScript engine wait for the user to acknowledge - which gives the IFrame time to set up.

You could try moving the copy line to the end of the document - see if that has any effect. Either that, or
add a pause or checking routine in somewhere.

HTH,
JP

7:58 pm on Mar 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


Or, just call the frame like this:

framename.document.write(document.frmInsert.txtBody.value);

8:12 pm on Mar 7, 2003 (gmt 0)

New User

10+ Year Member

joined:June 16, 2002
posts:13
votes: 0


Hi Jpjones,
the pause just worked fine, thanx

Pete