繁体   English   中英

检索由ajax调用填充的选择框的值

[英]Retrieving value of a select box populated by an ajax call

这是两个选择框。 我试图获得C的值以一种形式传递。 选择框C从下面的ajax调用中填充,但是我似乎无法获得有用的值来传递给表单。 (以最简单的形式,我正在寻找类似var A ='select box C'的东西),然后可以以以下形式发送“ A”:

预先感谢大家x

<select name="list-select" id="list-select">
    <option value="">Please select..</option>
    <option value="Chemical">Chemical</option>
    <option value="Hardware">Hardware</option>
</select>

<select name="C" id="C"></select>

这是jquery位:

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    $(document).ready(function ($) {
        var list_target_id = 'C'; //first select list ID
        var list_select_id = 'list-select'; //second select list ID
        var initial_target_html = '<option value="">Please select a colour...</option>'; //Initial prompt for target select

        $('#' + list_target_id).html(initial_target_html); //Give the target select the prompt option

        $('#' + list_select_id).change(function (e) {
            //Grab the chosen value on first select list change
            var selectvalue = $(this).val();

            //Display 'loading' status in the target select list
            $('#' + list_target_id).html('<option value="">Loading...</option>');

            if (selectvalue == "") {
                //Display initial prompt in target select if blank value selected
                $('#' + list_target_id).html(initial_target_html);
            } else {
                //Make AJAX request, using the selected value as the GET
                $.ajax({
                    url: 'http://www.mypropertyviewing.com/Client_order_form_v1.1/selector.php?svalue=' + selectvalue,
                    success: function (output) {
                        $('#' + list_target_id).html(output);
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(xhr.status + " " + thrownError);
                    }
                });
            }
        });
    });
</script>

采用

selectvalue=this.value //instead  of
selectvalue =$(this).val();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM