Click to See Complete Forum and Search --> : changing already loaded text


milf
12-28-2002, 10:25 AM
I'm looking to change a block of text using javascript. I'd prefer to use this method as opposed to refreshing the page each time.

I basically want to be able to change the content of a block of text depending on when a visitor clicks a link. The idea is that the visitor can sort navigate through journal entries by clicking on a link. Clicking a link will bring that entry to the main section of the page.

I've seen this done before and I think I had it working on IE, but something still isn't right. Here's what I had:


function rewrite(title, text) {
document.all.mainText.innerText = text;
document.all.mainTitle.innterText = title;
}


I have to <span id="xxx"> tags in the HTML that represent mainText and mainTitle. I read somewhere that document.all is a MS thing and probably won't be supported by all browsers. Is there a workaround to this?

Could someone suggest a better approach. I'm open to suggestions so long as I don't have to refresh the page each time. I'd prefer it to be dynamic.

Thanks!

khalidali63
12-28-2002, 10:41 AM
Instead of

function rewrite(title, text) {
document.all.mainText.innerText = text;
document.all.mainTitle.innterText = title;
}

you can use document.getElementById

function (title,text){
document.getElementById("mainText").innerHTML = text
//assuming the mainText is an id for an object
}

I am sure you know that changes made to the page like this are only in the browser memory,and if you had to come to the page this information won't be there.

milf
12-28-2002, 11:30 AM
Yes, I know that these changes are not permanent. That's fine, I don't want them to be.

I tried the code that you posted and that worked well. I'm using Chimera, but do you know how well this work with other browsers? I want a solution that is pretty general so that most any visitor will be able to use the page.

Thanks.

khalidali63
12-28-2002, 11:34 AM
this solution will work with IE5+ and NS6+, I am hoping it will work with Opera because that to me seems like another IE browser(*_*). to make this work with NS4 type of browsers you will have to do some coding..:-)

Khalid