/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to trigger on change on Hidden input?

[CODE]<input type=”hidden” onchange=”some function”>
[/CODE]

Is it possible to trigger the some function from a hidden field? I tried to change the value by javascript and call focus(), blur in order, seems nothing happen, fro m W3c, it does not say that the hidden field can not trigger onchange, Is it possible?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Nov 30.2006 — If you are setting the hidden, than you hsould not have to call onchange since you can call it where the value is being set.

Eric
Copy linkTweet thisAlerts:
@mrhooNov 30.2006 — if you change, with [B]script[/B], the value of [B]any [/B] input field- hidden or text or select or whatever, the onchange event isn't fired.

Hidden elements don't show up when you tab through a form's elements, so I would guess they don't have any use for focus, either.

This is a silly question.
Copy linkTweet thisAlerts:
@philip_snyderDec 12.2009 — This actually is not a silly question. There are times when you might want to chain a series of functions together based entirely on a value set in a hidden element by a different section of javascript code. A solution to your problem is to use a text input and set the css display to 'none'.
Copy linkTweet thisAlerts:
@A1ien51Dec 12.2009 — You replied to a 3 year old question. lol
Copy linkTweet thisAlerts:
@philip_snyderDec 12.2009 — Ok, so I'm the silly one now I guess. I forgot to mention something. You do have to invoke the element's onchange() method. But if you do it like I have described below, you'll get exactly what you're looking for.

[code=html]
<html>
<head>
<script>
var currVal = 0;
function changeIt() {
document.getElementById('changeMe').value = currVal++;
document.getElementById('changeMe').onchange();
}
function handle_change(elem) {
alert(elem.value);
}

</script>
</head>
<body>

<input type="button" onclick="changeIt()" value="Change It"/>
<input id="changeMe" type="text" value="" style="display: none;" onchange="handle_change(this)"/>

</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@philip_snyderDec 12.2009 — It may be a 3 year old question... but the previous answers inspired me to do better.
Copy linkTweet thisAlerts:
@wakkiJan 05.2010 — agree. this may be a 3 yr old question but the answer is very useful.. thanks for answering this post. i was searching for codes from google and found this thread.. i also have the same question.

(Is it possible to trigger on change on Hidden input?)

can i use hidden input instead of using text input and using ccs?
×

Success!

Help @zeeho_81 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.16,
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,
)...