Fire the TextChanged event of a texbox from Javascript

Rattlesnake

Freshman
Joined
Dec 23, 2003
Messages
47
Hi,
I have an ASP.NET 1.1 form
It contains the following controls
1. Quantity (textbox)
2. ETD (textbox)
3. Customer (dropdown)

I have a TextChanged for the Quantity control that runs a Server procedure "RUNCHECKS"

The ETD is a Date field. The user cannot enter the date into this field manually . I have an image on the form that when the user clicks on opens up a pop-up calender and he selects the date from the calendar. When a date is selected it is automatically assigned to the ETD textbox.This is all done using Javascript

How can I fire the TextChanged event for the ETD textbox control that will run the "RUNCHECKS" method.

Thanks
 
Hack alert!

This is a bit of a hack; there may be a neater solution.

What you need to do is find the Javascript code that is generated to cause the autopostback for the Quantity textbox. You will probably find it in the onchange attribute of the HTML input element. Then, using the same code you can invoke the change event (of the Quantity textbox) in your own Javascript. With a little straightforward modification, you can trigger events for other controls, such as the ETD textbox.

The generated Javascript may look something like

Code:
__doPostBack("ctl00_content_Quantity", "")

Or it could be something more complex like

Code:
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("controlname", "", false, "", "Page.aspx", false, true));

Either way, it is fairly simple to see what is happening. Like I said, it is a bit of a hack, but it does work. Just remember to change the Javascript if you rename your controls.

Good luck :cool:
 
Hi MrPaul,
The date for ETD will be selected from a pop-up window that contains a calendar control. When the user selects a date in the pop-window a javascript function assigns the selected date to the ETD control in the calling form like below

Code:
function SetDate()
     {
       window.opener.document.forms["<%= FormName %>"].elements["<%= ControlName %>"].value = "<%= SelectedDate %>";
       window.close();
     }

Can I call the __doPostBack("ctl00_content_Quantity", "") function from the pop-up window ??

Thanks
 
Unsure about popups

My knowledge of the relationship between popup windows and their parent windows is limited, so I can't say for sure whether that would work.

Note that when I mentioned __doPostBack("ctl00_content_Quantity", ""), that was purely an example. This statement will not work for you - it will cause a postback, but not raise any events. You have to find the correct function call from the onchange attribute of the element which represents the Quantity textbox in the HTML, and use that.

As I said, I don't know much about popups, but I can think of some other hacks to work around the problem, such as using setTimeout to periodically check whether the contents of the ETD textbox has changed, and then cause a postback when it does.

Sorry I couldn't be more help...
 
Back
Top