homepage Welcome to WebmasterWorld Guest from 54.234.0.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
onload javascript -- writes textbox content into a frame
only works when I precede it with an alert()
lizard




msg:1475848
 10:20 am on Mar 7, 2003 (gmt 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

 

SethCall




msg:1475849
 3:29 pm on Mar 7, 2003 (gmt 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...

lizard




msg:1475850
 4:50 pm on Mar 7, 2003 (gmt 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.

jpjones




msg:1475851
 4:53 pm on Mar 7, 2003 (gmt 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

DrDoc




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

Or, just call the frame like this:

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

lizard




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

Hi Jpjones,
the pause just worked fine, thanx

Pete

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved