views:

78

answers:

4

Below is the jquery script that takes one input value from textBox1 and pass it to a web method then returns the name of the person and displays it in textBox2. The web method only takes one parameter, the user initials.

<script type="text/javascript" >   
    $('#textBox1').live('keydown', function(e) {
        var keyCode = e.keycode || e.which;
        if (keyCode == 9) {
            e.preventDefault();

            $.ajax({
                type: "POST",
                url: "Default.aspx/GetName",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{"value1":"' + $('#textBox1').val() + ' " }',
                success: function(data) {
                    $('#textBox2').val(data.d);
                }
            });
        }
    });    
</script>

I want to be able to pass two values from two textboxes for a web method that requires two parameters. how can I modify the jquery code above to accomplish that?

A: 

Is this what you mean?

<script type="text/javascript" >   
    $('#textBox1').live('keydown', function(e) {
        var keyCode = e.keycode || e.which;
        if (keyCode == 9) {
            e.preventDefault();

            $.ajax({
                type: "POST",
                url: "Default.aspx/GetName",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{"value1":"' + $('#textBox1').val() + '", "value2":"' + $('#textBox2').val() + '" }',
                success: function(data) {
                    $('#textBox2').val(data.d);
                }
            });
        }
    });    
</script>
Drew Wills
+3  A: 

You add the parameters to the data object, which by the way should be an object:

data: { value1: $('#textBox1').val(), value2: $('#textBox2').val() },
Guffa
A: 

I'd use something like jQuery Json

Paul Creasey
How would you use it?
Bartek Tatkowski
A: 

thank you Drew Wills, it works !!! thank you. The browser somehow deleted the history and now i can't mark your answer as the one that solved my problem.

thanks a lot again.

Kintaro