/    Sign up×
Community /Pin to ProfileBookmark

Setting CHECKED = TRUE with onchange event on a text box

I have a question which I am not sure if it is even possible.

I have a check box with an associated text field.

I created what I thought was a function that changes the state of that checkbox to checked when an ‘onChange’ event happens on the associated text box.

I can’t seem to get it to work how I think it should.

I am a PHP guy with limited Javascript experience who would love to help anyone with PHP if they could help me with some of my Javascript questions.

Thanks!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvSep 05.2004 — Welcome to the forums.

Perhaps something like this will get you on the right track?<form action="#">
<fieldset>
<legend>Demo</legend>
<input type="checkbox" id="box" name="box">
<label for="data">Data: <input type="text" id="data" onchange="document.getElementById('box').checked=true"></label>
<input type="submit" value="Submit">
</fieldset>
</form>
P.S. Note that [font=courier]onchange[/font] fires when you [i]leave[/i] the field, not when you're typing into it.
Copy linkTweet thisAlerts:
@lostjavaguyauthorSep 05.2004 — Thanks for the quick response.

Works like a charm.

I was overthinking it but the way you were firing that even has really enlightened me on some things.

Thanks again for your quick response.

For those who see this thread note that there are a couple of tags that aren't required for this to work. The <fieldset> <legend> and <label> tags are ways to group form information together and not required for this to work properly.

I can't give you a full explanation on those tags but I am sure you can find that elsewhere.

Thanks,
×

Success!

Help @lostjavaguy 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.18,
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,
)...