Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#825042
Hi all,
I've a strange behavoir with this piece of code (is an example, in production it doesn't show an alert but it set other values for other fields on the same row):
Code: Select all
$("form").setOnchange(modifiedForm);
function modifiedForm(fieldId, newVal, oldVal){
    console.log("fieldId: " + fieldId + " - newVal: " + newVal + " - oldVal: " + oldVal);
    if (oldVal != ''){
        rowID = (fieldId.substring(16,fieldId.length)).substring(0,(fieldId.substring(16,fieldId.length)).indexOf(']'));
        fieldTemp = ((fieldId.substring(16,fieldId.length)).substring(fieldId.substring(16,fieldId.length).indexOf('[')+1));
        field = fieldTemp.substring(0,fieldTemp.length-1);

        if (newVal!=oldVal){
			if (newVal > 500){
				alert("New value>500!");
			}
        }
    }
}
In brief, it works fine when I make changes but when I remove a row the content of fieldId contain the old index row.
Anyone can help me to understand why and how I can resolve it?!?

Thanks!
#825085
I don't understand your question.

Is this what you want to do?
Code: Select all
$("form").setOnchange(modifiedForm);
function modifiedForm(fieldId, newVal, oldVal) {
   //check if changing a particular field in the grid.
   //change myGrid and myField to the IDs of your grid and your grid field.
   var aMatch = fieldId.match(/^\[myGrid\]\[(\d+)\]\[myField\]$/);
   
   if (aMatch && oldVal != '') {
        var rowNo = aMatch[1];

        if (newVal != oldVal) {
             var newValue = parseInt(newVal);

	     if (newValue > 500) {
		 alert("New value in row "+rowNo+" is over 500. Setting to maximum of 500");
                 $("#myGrid").setValue(500, rowNo, 3); //change 3 to the column number of grid that you want to change
	     }
        }
    }
}
#825091
Thanks for your reply,
no, the problem is that if you add more than one row and you exec the code you will have, modifying the 5th row, rowNo=5.
If you delete one row (from 1 to 4) and try to modiy the new 2nd row you have the same rowNo=5 when I'm expecting rowNo=2.
I hope I was clear.
#825100
You can try using this:
Code: Select all
var formId = $("form").prop("id");
$("#"+formId).change( function(e) {
  var val = e.target.value;
  var aMatch = e.target.id.match( /^form\[clientList\]\[(\d+)\]\[(\w+)\]$/ );
  
  if (aMatch) {
    var rowNo = aMatch[1];
    var gridFieldId = aMatch[2];
    alert("Field "+gridFieldId+" in row "+rowNo+" was changed to '"+val+"'");
  }
});
Where "clientList" is the ID of the grid.

I don't know how to get the previous value, but this will get you the row number and ID of the field in the grid.

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]