/    Sign up×
Community /Pin to ProfileBookmark

[HELP]A Question when using javascript in FORM

[code]

<form name=form>
<input type=”text” name=[color=blue]name[/color] size=27>
<input type=”button” value=”What’s your name?”
onClick=”document.form.text.value=[color=red]’value'[/color]”>
<input type=”text” name=text>
</form>

[/code]

What i need to do to change the [color=red]‘value’[/color] to the texts in the [color=blue]name[/color]

Thanks^^ ?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinSep 03.2006 — try:

<i>
</i>onClick="document.form.text.value=this.previousSibling.name"
Copy linkTweet thisAlerts:
@fattyghost007authorSep 03.2006 — Eh...

may be just now my words got abit complicated..

but wad i mean is when i press "What's your name" button,

The words in text (with the name "name") will shown at the text (with the name "text")
Copy linkTweet thisAlerts:
@KorSep 03.2006 — <i>
</i>&lt;form name="form"&gt;
&lt;input type="text" name="name" size=27&gt;
&lt;input type="button" value="What's your name?"
onclick="this.form['text'].value=this.form['name'].value"&gt;
&lt;input type="text" name="text"&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@KorSep 03.2006 — [COLOR=Navy][B]this[/B].form[/COLOR]

is the reference for the object [B]form[/B]
Copy linkTweet thisAlerts:
@fattyghost007authorSep 03.2006 — So...the [color=red]form[/color] in "this.[color=red]form[/color]" is not a name,right?

How the codes should become if i replace the 3rd input with a textarea(if the textarea name is textarea1)?
Copy linkTweet thisAlerts:
@KorSep 03.2006 — right

this.form is a native reference. It will reference the form nomatter it's name

The code will be the same. change the name

onclick="this.form['textarea1'].value=this.form['name'].value"

In fact you could even don't use [B]this.form[/B] reference as, by default, elements referenced by an event placed insided another form's element, have the root the form itself. But to use this shortcut, make sure your elements have not native or reserved javascript words as names. Don't name your form name="form" or name="name" or name="text".
<i>
</i>&lt;form name="myform"&gt;
&lt;input type="text" name="myname" size=27&gt;
&lt;input type="button" value="What's your name?"
onclick="mytext.value=myname.value"&gt;
&lt;input type="text" name="mytext"&gt;
&lt;/form&gt;
×

Success!

Help @fattyghost007 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...