I am very new to MooTools and fairly new to JavaScript.
I have created a template that displays a row on the click on a button. Each time the button is clicked, another row appears.
One of the fields in the template is a reference number that is generated by calling an existing PHP script. The problem is that I keep getting the same number in every row. I want to have a way to check the value of the field and increment the same field in the following row by 1, but I don't know how to do that.
I tried using MooTools to do something on load, but that didn't work.
Here is the template. The <?php echo $this->MJob->getNewJobRef(232); ?>
is what gets the autogenerated reference number.
<script id="connectedjobtemplate" type="text/template">
<tr id="childjobrow<%= rownum %>" class="<%= cl %>" data-row-id="<%= rownum %>">
<td colspan="7">
<table width="100%">
<tr>
<td style="width: 15%;">
<input class="childjobid" type="hidden" id="childjobid<%= rownum %>" name="childjobid[<%= rownum %>][transcribername]" value="0" />
<input type="hidden" id="transcriberid[<%= rownum %>]" name="childjobid[<%= rownum %>][transcriberid]" value="" />
<input data-row-id="<%= rownum %>" id="assignee[<%= rownum %>]" name="childjobid[<%= rownum %>][transcribername]" class="" list="transcribers" autocomplete="off" value="" placeholder="Name" size="14" />
</td>
<td style="width: 15%;">
<input data-row-id="<%= rownum %>" id="reference[<%= rownum %>]" name="childjobid[<%= rownum %>][reference]" value="<?php echo $this->MJob->getNewJobRef(232); ?>" class="ref" size="14" style="background-color: transparent; border: none;" />
</td>
<td style="width: 5%;">
<input data-row-id="<%= rownum %>" id="pages[<%= rownum %>]" name="childjobid[<%= rownum %>][pages]" value="" class="" style="" size="2"/>
</td>
<td style="width: 15%;">
<input data-row-id="<%= rownum %>" id="orderDate[<%= rownum %>]" name="childjobid[<%= rownum %>][orderDate]" value="" class="" size="12" />
</td>
<td style="width: 15%;">
<input data-row-id="<%= rownum %>" id="nysid[<%= rownum %>]" name="childjobid[<%= rownum %>][nysid]" value="<%= nysid %>" class="" size="12" />
</td>
<td style="width: 15%;">
<input data-row-id="<%= rownum %>" id="dinNum[<%= rownum %>]" name="childjobid[<%= rownum %>][dinNum]" value="" class="" size="12" />
</td>
<td style="width: 15%;">
<input data-row-id="<%= rownum %>" id="warrantNum[<%= rownum %>]" name="childjobid[<%= rownum %>][warrantNum]" value="" class="" size="12" />
</td>
</tr>
</table>
</td>
</tr>
</script>
I tried adding this, but it didn't work:
$('#ref').addEvent('load', function(e, el) {
alert('Here');
});
I guess I am confused about how to check if that field is loaded, unless there is something wrong in my syntax. I also tried replacing '#ref'
with document.body
, but it still doesn't work. Should I rather be using code in the template itself to check this?