Search code examples
javascriptscriptlet

Scriptlet and values for an input box


I am using DataTables on a page and am having it fill itself in by collecting data from a spreadsheet. The code currently looks like this:

 <tbody>
    <? var stringified1 = getDataJobNumbers(); ?>
    <? var stringified2 = getDataCustomerName();?>
    <? var stringified3 = getDataQuantity();?>
    <? var stringified4 = getDataInsertNumber();?>
    <? var stringified5 = getDataHours();?>
    <? var stringified6 = getDataDriverHours();?>
    <? var stringified7 = getDataDate();?>
     <?var job = JSON.parse(stringified1)?>
     <? var customer = JSON.parse(stringified2)?>
     <? var quantity = JSON.parse(stringified3)?>
     <? var inserts = JSON.parse(stringified4)?>
     <? var hours = JSON.parse(stringified5)?>
     <? var driverHours = JSON.parse(stringified6)?>
     <? var date = JSON.parse(stringified7)?>

        <? for (var i = 0; i < job.length; i++) { ?>
       <tr>
       <td><?= job[i] ?></td>
       <td><?= customer[i] ?></td>
       <td><?= date[i] ?></td>
       <td><?= quantity[i] ?></td>
       <td><?=inserts[i]?></td>
       <td><?= hours[i] ?></td>
       <td><?= driverHours[i] ?></td>
       </tr>

          <? } ?>

    </tbody>

Now, what I would like to do is have the inserts, hours, and drive hours actually show up as input boxes. Normally I would do this:

<td><input type="text"></td>

and leave it at that. But I would like for the any value that might currently be in the spreadsheet to show up as the default value in the input box.

This obviously doesn't work:

<td><input type=text value="<?=inserts[i]?>"></td>

However, I'm not sure what would. Any pointers in the right direction would be appreciated. Scriptlets are still a bit of a gray area in my understanding.


Solution

  • Apparently I had a typo...

    <td><input type="number" value="<?=inserts[i]?>"></td>
    

    works just fine.