Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

javascript equivalent to visual basic textbox textchanged event

I'm using asp.net web forms and visual basic.

On my page i have a ASP Textbox.

I'm using the TextChanged event.

This is my code:

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs)


        HiddenField_TextBox1Changed.Value = TextBox1.Text

    End Sub

So when I type some text in the textbox, the textchanged event is saving the value I typed in the textbox, to a hidden field.

What's the equivalent to the TextChanged event of a textbox using JavaScript instead of Visual Basic?
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would suggest the use of `addEventListener()` method instead, the inline-event as `onchange / on..` is the old-fashioned way to attach the event to an element from the HTML side, it's better to separate the HTML/JS and attach your event from the JS side, for the event you better using the `input` event since it's more efficient when tracking the user inputs, and if you want to update the hidden field once the user quit the field it will be better to use `blur` the opposite of focus, something like :

document.querySelector('[name="TextBox1"]').addEventListener('input', function(){
     document.querySelector('[name="HiddenField_TextBox1"]').value = this.value;
});

Open in new window