Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change form text

Status
Not open for further replies.

rr236

IS-IT--Management
Oct 23, 2000
37
0
0
GB
Is it possible to change the text on a form using javascript?

There are 2 examples I have that need this function.

I have a simple form that displays the time a user has opened the form. I'd like to update this the current time.

My second example relates to closing a window. I have a form that contains a button that opens a new window. On closing the opened window I would like to print the return variable from the window.

thanks
RR236

If so how?
 
1. yes - suppose you have a field named "time":
<input type="text" name="time" />

reference it like so:
Code:
document.[i]formName[/i].time.value = new Date();
2. yes - in your popup window, use something similar to:
Code:
opener.[i]document.formName.[/i]fieldName.value = someNewValue;
window.close();

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
oops... that second part should read
Code:
opener.document.[i]formName.fieldName.[/i]value = someNewValue;
window.close();

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Jemminger

thanks for the reply. However I should have been more explicit in my description of the problem.

The text on the form is just that, text. I am not using input fields as I am trying to fit a lot of data on screens.

Any idea as to how the text can be changed.

thanks
rr236
 
you can put the text in an element with an id, then use getElementById() and change the innerHTML

<div id="foo">this is the old text</div>

Code:
document.getElementById("foo").innerHTML = "this is the new text";

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Excellant. Many thanks.
rr236
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top