Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q918 How can I display the value of a form field in the document body when a form button is pressed?

irt.org | Knowledge Base | DHTML | Q918 [ previous next ]

Q918 How can I display the value of a form field in the document body when a form button is pressed?

The following will work in Netscape Navigator 4 and Internet Explorer 4:

<script language="JavaScript"><!--
function changeContent(id,text) {
    if (document.all)
        document.all[id].innerHTML = text;
    else if (document.layers) {
        document.layers[id].document.open();
        document.layers[id].document.write(text);
        document.layers[id].document.close();
    }
}
//--></script>

<form>
<input type="text" name="fieldName">
<input type="button" value="Change" onClick="changeContent('firstname',this.form.fieldName.value)">
</form>

<div id="firstname"><layer id="firstname">xyz</layer></div>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.