|
-
set onchange event
Hello,
Probably a stupid question, but how do I set the onchange event of an element I have created in javascript?
var nextInput = document.createElement('input');
nextInput.setAttribute('name', 'picture[]');
nextInput.setAttribute('type', 'file');
I would like the nextInput element to have an onchange attribute.
I tried
nextInput.setAttribute('onChange', 'myFunction');
but this does not work.
Any ideas?
Thanks,
Smintheu
-
 Originally Posted by Smintheu
I tried
nextInput.setAttribute('onChange', 'myFunction');
but this does not work.
onchange is not an attribute -- it is an event. One way to do it is as follows:
nextInput.onchange = myFunction;
Note the lack of () on the function. This is on purpose.
-
That did the trick, thanks a lot!
Smintheu
-
how then do you pass arguments with this function?
Thanks,
Smintheu
-
Code:
nextInput.onchange = function(){myFunction(this);};
At least 98% of internet users' DNA is identical to that of chimpanzees
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks