开发者

passing multiple values from multiple textboxes in jquery

开发者 https://www.devze.com 2022-12-18 20:34 出处:网络
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

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?


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

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


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>


I'd use something like jQuery Json

0

精彩评论

暂无评论...
验证码 换一张
取 消