Call Javascript onchange event by programmatically changing textbox value

前端 未结 8 1156
心在旅途
心在旅途 2020-11-30 08:59

the problem I\'m facing is this:

  • I have a textbox for a date range along side a calendar control.
  • When the user selects a date from the calendar, it
相关标签:
8条回答
  • 2020-11-30 09:38

    You're population is from the server-side. Using the registerclientscript will put the script at the beginning of the form.. you'll want to use RegisterStartupScript(Block) to have the script placed at the end of the page in question.

    The former tries to run the script before the text area exists in the dom, the latter will run the script after that element in the page is created.

    0 讨论(0)
  • 2020-11-30 09:41

    Onchange is only fired when user enters something by keyboard. A possible workarround could be to first focus the textfield and then change it.

    But why not fetch the event when the user clicks on a date? There already must be some javascript.

    0 讨论(0)
  • 2020-11-30 09:43

    You're misinterpreting what the onchange event does when applied to a textarea. It won't fire until it loses focus or you hit enter. Why not fire the function from an onchange on the select that fills in the text area?

    Check out here for more on the onchange event: w3schools

    0 讨论(0)
  • 2020-11-30 09:45

    You can fire the event simply with

    document.getElementById("elementID").onchange();
    

    I dont know if this doesnt work on some browsers, but it should work on FF 3 and IE 7+

    0 讨论(0)
  • 2020-11-30 09:53

    You can try the Anthem library.

    0 讨论(0)
  • 2020-11-30 09:54

    The "onchange" is only fired when the attribute is programmatically changed or when the user makes a change and then focuses away from the field.

    Have you looked at using YUI's calendar object? I've coded up a solution that puts the yui calendar inside a yui panel and hides the panel until an associated image is clicked. I'm able to see changes from either.

    http://developer.yahoo.com/yui/examples/calendar/formtxt.html

    0 讨论(0)
提交回复
热议问题