2017-12-27 11 views
0

Ich habe eine HTML-Tabellenzeile mit Zellen gemischten Inhalts nach Bedarf angepasst. Ich möchte diese Zeile dynamisch zur HTML-Tabelle hinzufügen. Aber ein Fehler taucht in der js auf.Hinzufügen von benutzerdefinierten Tabellenzeile zu HTML-Tabelle in PHP

die PHP-Funktion ist als

function addRowtoTable(){ 
    $tblRow = '<tr> 
       <td><input type="checkbox" name="record"></td>  
       <td for="section"><select name=\'section\' id=\'section\' class=\'form-control\' >  
          <?php echo fill_sectionName($conn, $userRow[\'userName\']); ?></select></td> 
       <td for="fileRef"><input name ="fileRef" id="fileRef" class="form-control ui-autocomplete-input" autocomplete="on" placeholder="Enter File Reference"></td> 
       <td for="datepicker"><input class=\'form-control\' type="text" id="datepicker" placeholder="Mail Date"></td>     
       <td for="section"><?php echo fill_SecurityClass(); ?></td>  
       <td for="section"><?php echo fill_Precedence(); ?></td> 
       <td for="section"><?php echo fill_AppointmentList($conn); ?></td> 
       <td for="section"><input name ="address1" id="address1" class="form-control ui-autocomplete-input" autocomplete="on" placeholder="Enter Stn Name"></td> 
       <td for="section"><?php echo fill_ModeOfDespatch(); ?></td> 
      </tr> 
        '; 
    return ($tblRow); 

folgt Bitte beachten Sie, dass ich für das Füllen der automatischen Vervollständigung, Datumsauswahl und wählen Sie Objekte PHP-Funktionen im HTML-Code nenne.

Das JS-Skript die diese <tr> in meiner Tabelle hinzuzufügen, ist wie folgt:

$('#addtblRow').click(function() { 
    var tblRowNew = <?php echo addRowtoTable()?> ; 
    $("table tbody").append(tblRowNew); 
    }); 

Der Screenshot der Fehlermeldung des Browsers ist wie dieser

screenshot of the error message

Kann ich helfen Sie diesen Fehler zu beheben.

Antwort

0

Ich habe einen anderen Ansatz gemacht. In PHP erklärt i Variablen

<?php 
    global $sectionNames; 
    global $Prece; 
    global $AddeeAppt; 
    global $ModesOfDes; 

    $sectionNames = fill_sectionName($conn, $userRow["userName"]); 
    $Prece = fill_Precedence(); 
    $AddeeAppt = fill_AppointmentList($conn); 
    $ModesOfDes = fill_ModeOfDespatch($conn); 
?> 

$("#addtblRow").click(function(){ 
     var numofrows = $("#num_rows").val(); 
     //window.alert(numofrows); 
     for(var i=0;i<numofrows ;i++){ 
     addNewRow(); 
     } 
    }); 

Die JS wurde wie dieser modifizierten

function addNewRow(){ 
    // 
    var trd=""; 
    trd +="<tr>"; 
    trd +="<td><input type='checkbox' name='record' class='form-control' ></td>"; 
    trd +="<td for='section'><select name='section' id='section' class='form-control'><?php echo $sectionNames ?> </select></td>"; 
    trd +="<td><input name='fileRef' class='form-control'></td>"; 
    trd +="<td for='datepicker'><input class='form-control' type='text' id='datepicker' placeholder='Mail Date'></td>"; 
    trd +="<td><?php echo $Prece ?></td>"; 
    trd +="<td><?php echo $AddeeAppt ?></td>"; 
    trd +="<td><input name='Address' class='form-control'></td>"; 
    trd +="<td><?php echo $ModesOfDes ?></td>"; 
    trd +="</tr>"; 
    $("table tbody").append(trd); 
} 

Und der Code funktioniert gut für mich. PS: Der JS erlaubt Wagenrücklauf in seinen Variablen nicht. Also sollen alle HTML Elemente/Tags zusammenhängend sein.

Verwandte Themen