Send value of button to JS to load DIV content

12 views
0

I am trying to send the value of the selected option to an new DIV to dynamic load an drop down menu.
The DIV is triggered but the needed value is not send to this new DIV.
The problem is + $("#add_bedrijf_" + [i]).val()

What is the correct wat to send this?
(The other code is for manipulating the different classes, this is working correct.)

 <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>