1

I have a textbox that sets the onchange property but when i start typing in the textbox the onchange doesnt fire initially. it never fires whats going on?

Here is the code:

VB.NET

      Dim textBoxUrlYoutube As New TextBox
      divUrlTextBoxContainer.Controls.Add(textBoxUrlYoutube)
      textBoxUrlYoutube.CssClass = "textboxyoutubeurlmediaselector"
      textBoxUrlYoutube.Attributes.Add("onchange", 
                                       "YoutubeUrlSaveTextBoxOnChange(this)")

JAVASCRIPT

function YoutubeUrlSaveTextBoxOnChange(el) {

    var text = $(el).val();

    if (text == '') {

        $("a.linkplayyoutubeurl2").attr("class", "linkplayyoutubeurl1");
        $("div.divlinktext2").attr("class", "divlinktext1");

    }
    else {

        $("a.linkplayyoutubeurl1").attr("class", "linkplayyoutubeurl2");
        $("div.divlinktext1").attr("class", "divlinktext2");
    }

}
1
  • 1
    For problems with JavaScript interacting with HTML, show HTML and JavaScript … not server side code. Commented Feb 21, 2011 at 22:00

1 Answer 1

5

Change events fire when the focus is lost, if a change has occurred.

If you want a change to fire with every keypress, use the keypress event.

Sign up to request clarification or add additional context in comments.

2 Comments

Doward the problem with this keypress is that when you initally type a letter in te textbox the kepress event returns the text of the textbox to empty. i need a function that gets the value as sonn as the first charachter is typed in the textbox
Or these days more than 11 years later, the input event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.