views:

19

answers:

1

I have a form that contains a TextBox. A pop up window will return a value and put it into the TextBox. when this happens, i need to populate another control. I tried tried "OnChange" but it was not triggered . How this can be achieved?

+2  A: 

You can use onchange, but this usually won't wire until the box loses focus. There's also onkeyup, which you want to use if you want the new text immediately.

Can you control the window populating the textbox? If so that's your best route, since it's the source of the event, just invoking the third control population from there, via a function in the parent page.

If there are no number based effects, you can bind the event to onchange, onclick and onkeyup to handle all cases, it'll run a bit extra, but if it's a lightweight operation, no multi-run side-effects and you want to cover your bases, it's a viable option.

Nick Craver
But onchange and onkeyup wasn't getting triggered in this scenario
Sri Kumar
@Sri - Can you post the code that's populating the textbox? It's hard to narrow down the exact best approach here with no code. It would be best to call it in there, since that's what's actually causing the text change to occur.
Nick Craver
Its a JavaScript date picker and was used universally in my project and its hard for me to change the date picker code :( If user selects the Start Date,by default the same date has to get populated in End Date too.
Sri Kumar
@Sri - I understand you may not be able to change it...but without code I can't help, it's like taking your car to a mechanic, saying it won't run, but not letting them see under the hood, they're just giving the best advice based on noises what's wrong.
Nick Craver
http://www.koders.com/javascript/fidE8AF1F4374699F2D54A34CA230275462C9912CA5.aspx?s=form#L31 You can find the coding here
Sri Kumar
@Sri - How are you calling this? The `callback` function is what you want to set, that function will run when a date is picked, e.g. `Calendar.setup({callback: myFunctionNameHere });`
Nick Craver
Calendar.setup ( { inputField : document.getElementById('ctl00_mainContentPlaceHolder_txtStartDate'), button : "btnStart" });
Sri Kumar
@Sri - Then change it slightly to use the `callback` option, like this: `Calendar.setup ( { inputField : document.getElementById('ctl00_mainContentPlaceHolder_txtStartDate'), button : "btnStart", callback: myFunction }); function myFunction() { //do stuff for other control here }`
Nick Craver
I tried to use this code displayArea : document.getElementById('ctl00_mainContentPlaceHolder_txtEndDate'), but failed. I am not sure how to get the value using your code
Sri Kumar