Fire event when textbox changes
Moderator: General Moderators
Fire event when textbox changes
Hi all,
I've got a textfield that is being updated with JS via a common calendar library. I'd like to fire an event when the contents of that textfield changes. I can't use onKeyUp() because text isn't being directly typed into the field. I can't use onChange() either because for textfields, onChange() is fired onBlur(). Since I'm never focusing on the field, onBlur() never fires.
Any ideas?
I've got a textfield that is being updated with JS via a common calendar library. I'd like to fire an event when the contents of that textfield changes. I can't use onKeyUp() because text isn't being directly typed into the field. I can't use onChange() either because for textfields, onChange() is fired onBlur(). Since I'm never focusing on the field, onBlur() never fires.
Any ideas?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
hm, give it temporary focus? onChange="textarea.focus(); this.focus();"
[[ my attempt
]]
[[ my attempt
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I could but don't want to for 2 reasons. 1) It's a 3rd party library - I'd have to wade through the code to set that up. 2) This may not be the only place I use that library, and I don't want to have it fire the event for other pages.
It is a bit wasteful of resources, but I could start the polling when the calendar is first loaded, and stop polling when the fields are validated.
Right now I'm thinking I just have a 'validate' button beside the dates - seems simplest.
It is a bit wasteful of resources, but I could start the polling when the calendar is first loaded, and stop polling when the fields are validated.
Right now I'm thinking I just have a 'validate' button beside the dates - seems simplest.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
so the ultimate goal is to validate that the dates are indeed dates? and you're doing that onblur of the field?
if so, just make sure that the dates are formatted correctly from the calendar, another 'easy' fix would be to modify your calendar libarary (very slightly) and make it send focus to the text field where the date is inserted. That should be a piece of cake.
But really, as long as you ensure the dates are formatted correctly from the calendar, then I don't see why you'd need to validate them anyway...
if so, just make sure that the dates are formatted correctly from the calendar, another 'easy' fix would be to modify your calendar libarary (very slightly) and make it send focus to the text field where the date is inserted. That should be a piece of cake.
But really, as long as you ensure the dates are formatted correctly from the calendar, then I don't see why you'd need to validate them anyway...
Yes I could, but that would require me changing the script that generates the calendar. As I mentioned, I might be using this JS library in other parts of this project, and I might not always want it to blur afterwards. I have updated the script to send the focus to the textfield it's updating - that seems like a more useful outcome.
Thanks - if this was a one-time usage I'd certainly give that a try.
Thanks - if this was a one-time usage I'd certainly give that a try.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.