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

Posting data from form to datatable using oncomplete()

user3536 Published in April 25, 2018, 12:21 pm

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

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);
    var diagCode = $('#modal-AddStudentDiagnosis_DiagCode-' + id).val();
    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 {
        // Reload the document view
        $('#detailPanel').fadeOut(500, function () {
        }).fadeIn(250, function () {

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 1.053091 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO