/    Sign up×
Community /Pin to ProfileBookmark

Force a onChange()

Is there any way to force an onChange() event for a select box on page load? I’m not able to set default values for the elements I intend to change. Thanks,
JW

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorNov 29.2008 — Just set the value in JavaScript if all you want to do is change the on/off state at start up.

If you want to simulate a user-click, it would depend on how complicated the onchange function is. If the onchange doesn't interact much with the event object, then you can probably call it directly. If the onchange interacts with the event a lot, then you need to create event object and call either "dispatchEvent" or "fireEvent"
Copy linkTweet thisAlerts:
@CuppyTeaNov 29.2008 — Is there any way to force an onChange() event for a select box on page load? I'm not able to set default values for the elements I intend to change. Thanks,

JW[/QUOTE]


Firing an onChange event will not change the value- as the event is fired ONchange, i.e. after the change, i.e. its all a bit backwards and won't work ?

Instead of using onChange, just loop through the options and set selected=true.
×

Success!

Help @JW_Burnside 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.19,
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,
)...