JQuery $('select').change has multiple values

62
June 13, 2018, at 5:20 PM

I'm new with Javascript and JQuery, so, I probably did something wrong and it causes my issue, explainations are below.

I am generating options for a select comparing to a first select value. When both options are choosen, the user has to press the submit button, and I'm receiving the right file content from PHP. But there's an issue : if the user is changing multiple times the dateChoiceSelect value, multiple values are stored in its .var(), and when these values are submitted, the PHP code is runned more than one time, how can I cope with it ?

Here's the code :

$(document).ready(function()
{
    $('#projectChoice').submit(function()
    {
        let valSelectProject=$('#projectChoiceSelect').val();
        $('#dateChoiceSelect').change(function()
        {
            let valSelectDate=$('#dateChoiceSelect').val();
            let dataToPHP = {choosenDate : valSelectDate, choosenProject 
            :valSelectProject};
            $.ajax({
                type:"POST",
                url:"js/json/pointsWhereDateExists.php",
                data:dataToPHP,
                success:function(returnedFromPHP)
                {
                    let listOfPoints = JSON.parse(returnedFromPHP);
                    $('#pointChoiceSelect').children().remove();
                    listOfPoints.forEach(function(element)
                    {
                        $('#pointChoiceSelect').append($('<option>',{value : 
                        element, text : element}));
                    }) 
                }
             });
             $('#pointChoice').submit(function()
             {
                 valSelectPoint = $('#pointChoiceSelect').val();
                 console.log(valSelectPoint);
                 let valFormat = $('#pointChoice 
                 input[name="choosenFormat"]:checked').val();
                 let dataToPHP = {choosenProject : valSelectProject, choosenDate : valSelectDate, choosenPoint : valSelectPoint, choosenFormat : valFormat};
                 $.ajax({
                    type:"POST",
                    url:"js/json/getAVGFileContent.php",
                    data:dataToPHP,
                    success:function(returnedFromPHP)
                    {
                        console.log(JSON.parse(returnedFromPHP));   
                    }
                 });
                 return false;
             });
        });
    });
});

Thanks in advance.

READ ALSO
Javascript objects combining with Jquery?

Javascript objects combining with Jquery?

I have an issue with manipulating data in Javascript/jQuery and I could use some help

62
jQuery resizable translateX [on hold]

jQuery resizable translateX [on hold]

currently I'm facing the issue that the resizable line (that ghost line) is way offset caused by transform: translateX is there any solution for that to recalculate the current position of the cursor?

50