Moussa
Moussa

Reputation: 71

Append into a table multiple inputs through javascript

I have a scenario which i have to use this way of appending lines into table The javascript isn't accepting any input type='text' , for unknown reason, If i put a normal text variable, it is working .I think there is a problem in single quotes / double quotes

  <?php
    for($counter=0;$row_work_entry=mysqli_fetch_array($run_work_entry);$counter++){
        $work_entry_days=$row_work_entry[0];
        $work_entry_type_id=$row_work_entry[1];
        $totalhours=date('h.i',strtotime($row_work_entry[2]));
        $name=$row_work_entry[3];
        $code=$row_work_entry[4];
        $workingdaystablelines.="<tr><td><input type='text'/></td><td>".$code."   </td><td>".$work_entry_days."</td><td>".$totalhours."</td></tr>";
     }

    ?>

<script>
    $(document).ready(function(){
         var workingdaystablelines ='<?php echo $workingdaystablelines;?>';
         $('#worked_days_table').append(workingdaystablelines);
    });
</script>

Upvotes: 0

Views: 70

Answers (1)

Jerson
Jerson

Reputation: 1745

I tested your code locally but single quotes gives me an error

 $(document).ready(function(){
   var workingdaystablelines = "<?php echo $workingdaystablelines;?>"
   $('#worked_days_table').append(workingdaystablelines)
 })

You may use double qoutes instead

and also you may use htmlspecialchars to avoid xss attack

echo htmlspecialchars($workingdaystablelines,ENT_QUOTES);

Upvotes: 2

Related Questions