/    Sign up×
Community /Pin to ProfileBookmark

How to pass input text to another textfield on same page?

I think this is a simple javascript behavior (?) but I can’t think of how to do it. I want to be able to have the input text appear in another area on the same page (with a text field or whatever) after the user clicks the “update” button. Is javascript most appropriate?

THanks
-Scott

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jan 18.2007 — Basic JavaScript with forms values:

document.forms[0].elementNameDestination.value = document.forms[0].elementNameSource.value;

Eric
Copy linkTweet thisAlerts:
@scottbaauthorJan 18.2007 — Thanks Eric. I assume I would put that line on the button? Here are my values:

input field - "phrase"

output field - "result"

form - "form1"

button - "submit"

Where you have forms[0] would I replace the 0 with "1" or "form1" to reference the form? Sorry, I'm pretty inexperience with writing javascript.

document.forms[1].result.value=document.forms[1].phrase.value; ?

Thanks

-Scott
Copy linkTweet thisAlerts:
@A1ien51Jan 18.2007 — arrays start at zero so the first form on the page is 0

only thing you need to change was the element names and stick it in your onclick event

Eric
Copy linkTweet thisAlerts:
@scottbaauthorJan 18.2007 — Ok. In IE7 nothing appears in the result field. In FireFox I see the text briefly in the results. I guess I'm missing something. Here's my code:
[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" name="form1" id="form1">
<input name="phrase" type="text" id="phrase" />
<input name="Submit" type="submit" onclick="document.forms[0].result.value = document.forms[0].phrase.value" />
<input name="result" type="text" id="result" />
</form>

</body>
</html>[/code]
×

Success!

Help @scottba spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...