views:

48

answers:

2

I have a asp.net input box:

<asp:TextBox ID="InCL" runat="server" Text=""></asp:TextBox>  

As soon as a number is entered I would like to send that value to a javascript function that updates a google gauge.

For example, user inputs 77, the google gauge immediately dynamically moves to that position.

Any help is appreciated.
Thank You.

EDIT
I'm looking at the onkeyup DOM event, is this a good way to go?

I think I'm just talking to myself on here.....

+2  A: 

Here is a script in jQuery I used to do something very similar. It does indeed use onkeyup to set the value; it also uses onkeydown to prevent non-numeric values; and forces a default value of 0 if the user tries to leave the textbox with no value:

var updateUI = function(value) {
    //set gauge
};

var textbox = $('#id_of_textbox)'

textbox.keydown(function(e) {
    return validNumberKeys.indexOf(e.which) > -1;
}).keyup(function(e) {
    var input = $(e.target);
    if(input.val() !== '') {
        updateUI(input.val());
    }
}).blur(function(e) {
    var input = $(e.target);
    if(input.val()==='') { input.val('0'); }
    updateUI(input.val());
});

var validNumberKeys = [8,9,13,16,17,18,35,36,37,38,39,40,45,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105];
Rex M
+1  A: 

You can do this:

<asp:TextBox ID="InCL" runat="server" onchange="YourJavaScriptFunction()" Text=""></asp:TextBox>

YourJavaScriptFunction() would then read the value out of InCL and do whatever you need to do with it.

You could also pass the value to your JavaScript like this: onchange="YourJavaScriptFunction(this.value)"

The same syntax will work with onkeyup: onkeyup="YourJavaScriptFunction()"

Andrew
PS One problem with OnKeyUp is that it won't work if the user pastes a value into the TextBox
Andrew
good point, thanks.
Greg McNulty
@Andrew, looks good, thank you.
Greg McNulty