将按钮值发送给JS以加载DIV内容

时间:2017-11-26 12:16:54

标签: javascript html

我正在尝试将所选选项的值发送到新的DIV以动态加载下拉菜单。 DIV被触发但是所需的值不会发送到这个新的DIV。 问题是+ $("#add_bedrijf_" + [i]).val()

发送此信息的正确值是多少? (另一个代码用于操作不同的类,这是正确的。)

 <div class="form-group col-md-6">
     <div class="form-group has-warning-add has-feedback" id="div_add_bedrijf" data-toggle="buttons">';
        $c = 0;

        foreach ($_SESSION['bedrijf'] as $value)
        {
            echo '<label class="btn btn-secondary" for="add_bedrijf_<?php echo $c;?>"><input type="radio" id="add_bedrijf_<?php echo $c;?>" name="add_bedrijf" value="'.$value.'" onmousemove="validate_add()" onblur="validate_add()"><img src="images/logo_'.$value.'_small.png" height="30"></label>';
            $c++;
        }
    echo '<span class="glyphicon glyphicon-warning-sign form-control-feedback" id="add_bedrijf_status"></span>
    </div>
</div>

<script type="text/javascript">
function validate_add()
{
    // Parent div of all buttons
    let div_add_bedrijf = document.getElementById('div_add_bedrijf');
    // Status div
    let add_bedrijf_status = document.getElementById('add_bedrijf_status');
    // A list with all the inputs that start the with id "add_bedrijf_"
    let elements = document.querySelectorAll('input[id^="add_bedrijf_"]');
    for(let i = 0; i < elements.length; i++) {
        let element = elements[i];
        // If the element is checked
        if(element.checked) {
            div_add_bedrijf.className = "form-group has-success has-feedback";
            add_bedrijf_status.className = "glyphicon glyphicon-ok form-control-feedback";
            $("#add_groep").load("includes/dynamic_drop/magazijn_magazijn_groep.php?choice=" + $("#add_bedrijf_" + [i]).val())
            // We found one was selected, so exit the loop
            return;
        } else {
            div_add_bedrijf.className = "form-group has-warning has-feedback";
            add_bedrijf_status.className = "glyphicon glyphicon-warning-sign form-control-feedback";
        }
    }
}
</script>

0 个答案:

没有答案