Home Posting data from form to datatable using oncomplete()
Reply: 0

Posting data from form to datatable using oncomplete()

RancorTamer
1#
RancorTamer Published in 2017-12-07 17:30:06Z

I am trying to take user entered data from a form elements and post it to a datatable using javascript. However, I cannot seem to have my function call correctly.

Here is my HTML:

  @using (Ajax.BeginForm("AddDiagnosis", "Student",
            new AjaxOptions(){
                OnSuccess = "HandleAddDiagnosisCode",
                OnBegin = "ValidateAddStudentDiagnosisCode(" + @studentId + ")"

            }, new
            {
                id = "AddStudentDiagnosis",
                name = "AddStudentDiagnosis"
            }
            ))
        {
        <div class="row">
          <div class="col col-sm-12">
            <div class="field padding-left-20">
              <label for="modal-AddStudentDiagnosis_DiagCode-@studentId">Code:</label>
              <select class="form-control" id="modal-AddStudentDiagnosis_DiagCode-@studentId" name="DiagCode">
                <option value="" selected>Select one...</option>
                <option value="V90.0">V90.0</option>
                <option value="V91.1">V91.1</option>
              </select>
            </div>
            <div class="field padding-left-20">
              <label for="modal-AddStudentDiagnosis_Sequence-@studentId">Sequence:</label>
              <select class="form-control" id="modal-AddStudentDiagnosis_Sequence-@studentId" name="Sequence">
                <option value="" selected>Select one...</option>
                <option value="1">Primary</option>
                <option value="2">Secondary</option>
                <option value="3">Tertiary</option>
                <option value="4">Quaternary</option>
              </select>
            </div>

and these are my javascript functions:

function ValidateAddStudentDiagnosisCode(id) {   
    var test = "test";
    var valid = true;
    var msg = "";
    var errorPanel = $('#modal-AddStudentDiagnosis-ErrorPanel');
    PopulateErrorMessage(errorPanel, msg);
    errorPanel.hide();
    var diagCode = $('#modal-AddStudentDiagnosis_DiagCode-' + id).val();
    //alert(diagCode);
    if (diagCode === "") {
        msg = "You must select a diagnosis code";
        valid = false;
    }
    var sequence = $('#modal-AddStudentDiagnosis_Sequence-' + id).val();
    if (sequence === "") {
        msg = "You must select a sequence";
        valid = false;        
    }
    if (valid == false) {
        PopulateErrorMessage(errorPanel, msg);      
    }    
    return valid;
}

function HandleAddDiagnosisCode(e) {


    var errorPanel = $('#modal-AddStudentDiagnosis-ErrorPanel');
    PopulateErrorMessage(errorPanel, '');
    var errorMessage = e.errorMessage;
    if (errorMessage.length > 0) {
        PopulateErrorPanel(errorPanel, errorMessage);
    }
    else {
        ClearModal();            
        // Reload the document view
        $('#detailPanel').fadeOut(500, function () {
            $(this).empty();
        }).fadeIn(250, function () {
            $(this).html(e.Html);
            BindDocumentEdit();
            BindDataTable();
            BindDatePickers();            
        });
    }
}

The validate code runs, because i can see the error message, However binding the data to the tables does not seem to be working. Am I making a mistake or is this not possible to do in this way?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309931 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO