This script would have to get the inputbox value, where id="{{probe.probeId}}"
In this inputbox "{{probe.probeId}}"
is getting data from the DB "probeID" when the value of the table column requires it. (If there is value, it shows it; if is empty, it lets you add a value; and the third option is if the value is null)
Then it has to compare this value with the max allowed value taken from the DB list where is stored
for (param in allparamArray)
{
var maxVal = param.ValorMaximo;
}
And then, when I put a value over the max value allowed (maxVal) in the inputbox, the cell will glow in red.
The problem is that when I put the "{{probe.probeId}}"
in the script function document.getElementById()
, it doesn't recognize the id value taken from the DB
How I can connect the javascript values with the ones taken by the twig table?
I was wondering if the answer given in here could be useful, but I don't know how to do it.
Here is an example (with the twig's fragment) of what I am doing: http://jsfiddle.net/wbh6T/2/
And it would be this simple without TWIG: http://jsfiddle.net/jBFHn/
The TWIG fragment is this:
{% for parameter in apparamlist %}
{% if parameter.parameterId in probe.parameterliste|keys %}
{% if probe.parameterliste[parameter.parameterId].ulockstatus ==2 %}
<td style='background-color:red;text-align:center;' title="{{probe.parameterliste[parameter.parameterId].comentario}}"><input class="resultfield" size='8' type='text' value="{{probe.parameterliste[parameter.parameterId].resultado}}" name={{parameter.parameterId}} id="{{probe.probeId}}"/></td>
{% else %}
<td style='text-align:center;'><input class="resultfield" size='8' type='text' value="{{probe.parameterliste[parameter.parameterId].resultado}}" name={{parameter.parameterId}} id="{{probe.probeId}}" /></td>
{% endif %}
{% else %}
<td> </td>
{% endif %}
{% endfor %}
And the Javascript:
window.onload = function () {
var textbox = document.getElementById("{{probe.probeId}}");
for (param in allparamArray)
{
var maxVal = param.ValorMaximo;
}
addEvent(textbox, "keyup", function () {
var thisVal = +this.value;
this.className = this.className.replace(" input-error ", "");
if (isNaN(thisVal) || thisVal > maxVal) {
this.className += " input-error ";
// Invalid input
}
});
};
function addEvent(element, event, callback) {
if (element.addEventListener) {
element.addEventListener(event, callback, false);
} else if (element.attachEvent) {
element.attachEvent("on" + event, callback);
} else {
element["on" + event] = callback;
}
}
Would this be a possible solution?-> Twig master usage