John Tantalo

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohn Tantalo
ToMe
Subjecthtml form question
Date30 April 2003 02:52 AM
I found your javascript tutorial very helpful. I have been playing around
with a combination of forms and javascript and I have a question. Is there
some way to output onto a page somewhere the result of some function,
without reloading the page, beside changing the value of a text field or
other trickery?

Thanks,
John Tantalo
FromMe
ToJohn Tantalo
SubjectRe: html form question
Date30 April 2003 08:56 AM
> I found your javascript tutorial very helpful

Thanks, I'll take that as a compliment.

>Is there some way to output onto a page somewhere the result of some function,
> without reloading the page, beside changing the value of a text field or
> other trickery?

Depending on how you want to do this, there are three ways.

    document.open();
    document.write('<html><body>'+outputResult+'</body></html>');
    document.close();
this will replace the entire page with the new content (not recommended)

    var x = window.open('','outputWin','options.....');
    x.document.open();
    x.document.write('<html><body>'+outputResult+'</body></html>');
    x.document.close();
this will open a window with the new content (recommended)

    ... <p id="someElementId"></p> ...

    if( document.getElementById ) {
        var x = document.getElementById('someElementId');
    } else if( document.all ) {
        var x = document.all['someElementId'];
    } else {
        var x = new Object();
    }
    x.innerHTML = outputResult;
this will change the HTML content of the given element with the new content.
This will NOT work in Opera 6-, Netscape 4, OmniWeb, Escape,  iBrow, Clue
browser and bugged WebTV. You can make it work in most layers browsers too
(Netscape 4, Escape, iBrow), but that is a little more complicated, and may
look a bit messy:

//as the page is loading
if( document.layers ) {
    document.write('<ilayer name="outerId">'+
        '<layer name="innerId">'+
        'Some initial content</layer></ilayer>');
} else {
    document.write('<p id="someElementId"></p>');
}

...

//to output the results
if( document.layers ) {
    var x = document.layers['outerId'].document.layers['innerId'];
    x.document.open();
    x.document.write(outputResult);
    x.document.close();
} else {
    if( document.getElementById ) {
        var x = document.getElementById('someElementId');
    } else if( document.all ) {
        var x = document.all['someElementId'];
    } else {
        var x = new Object();
    }
    x.innerHTML = outputResult;
}



Hope you find all of this useful, feel free to get in touch if I havn't
explained this well enough or if you need any more help.


Tarquin
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.