Paul Dessert
Paul Dessert

Reputation: 6389

Placing value in text field using datepicker and sending to function

How can I keep the value of the datepicker in the text area while using a function?

ex:

if($currentSelectionClass == "rowStartDate"){
    $('<input id="selectDateStart" type="text" />')
        .attr('name', 'editStartDate')
        .addClass('editStartDate')
        .appendTo(this)
        .datepicker({onSelect: startDateSubmit()});
    }

AND how would I send the datepicker value to my function?

Function code:

function startDateSubmit(){
            $selectDateStart = $('#selectDateStart').val();
            $.ajax({ 
                url: '/ajax/training-update.php',
                data: {action: $selectDateStart},
                type: 'POST',
                success: function(output) {
                    alert(output);
                    }
            });
        }

Upvotes: 0

Views: 326

Answers (1)

zerkms
zerkms

Reputation: 254916

  1. You need to specify reference to a function, not to call the function

    .datepicker({onSelect: startDateSubmit});
    
  2. You need to add argument to your function declaration

    function startDateSubmit(selectedDate) {
    

Upvotes: 2

Related Questions