Hello,
I need help or I'm looking for java script code for my my small project.
I do have a table named "LABEL" which has fields named - "BrokenJars", "LowVacuum", "Repack" and "Shrinkage"
1. I would like to make field "Shrinkage" as automated calculated field:
Shrinkage = BrokenJars + LowVacuum + Repack
2. Also, I would like to make the field Shrinkage as read-only field.
I will appreciate any suggestions or java script codes shared. Thanks in advance!
Java Script Calculated and Read-Only Field
Re: Java Script Calculated and Read-Only Field
Hi,
you can try to add this in the /hooks/<tablename>-dv.js
you can try to add this in the /hooks/<tablename>-dv.js
Code: Select all
(function(){
$j(function () {
$j('#Shrinkage').prop('readonly', true);
var update_Shrinkage= function () {
var v_BrokenJars = $j('#BrokenJars').val();
var v_LowVacuum = $j('#LowVacuum').val();
var v_Repack = $j('#Repack').val();
var v_Shrinkage = v_BrokenJars+v_LowVacuum+v_Repack;
$j('#Shrinkage').val(v_Shrinkage);
}
$j('#BrokenJars' ).on('change', update_Shrinkage);
$j('#LowVacuum' ).on('change', update_Shrinkage);
$j('#Repack' ).on('change', update_Shrinkage);
}
});
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Java Script Calculated and Read-Only Field
Thank you. I saved the code and refreshed the page but no changes happened.
Am I missing anything?
Am I missing anything?
Re: Java Script Calculated and Read-Only Field
Sorry there were some typos in the script.
Please use
Please use
Code: Select all
$j(function () {
$j('#Shrinkage').prop('readonly', true);
var update_Shrinkage= function () {
var v_BrokenJars = $j('#BrokenJars').val();
var v_LowVacuum = $j('#LowVacuum').val();
var v_Repack = $j('#Repack').val();
var v_Shrinkage = v_BrokenJars*1+v_LowVacuum*1+v_Repack*1;
$j('#Shrinkage').val(v_Shrinkage);
}
$j('#BrokenJars' ).on('change', update_Shrinkage);
$j('#LowVacuum' ).on('change', update_Shrinkage);
$j('#Repack' ).on('change', update_Shrinkage);
});
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Java Script Calculated and Read-Only Field
I'm still getting no changes. Below is my code. Please note that I added few fields and followed your code.
Also, I attached a screenshot of my label page.
$j(function () {
$j('#Shrinkage').prop('readonly', true);
var update_Shrinkage = function () {
var v_Repack = $j('#Repack').val();
var v_BrokenJars = $j('#BrokenJars').val();
var v_LowBrine = $j('#LowBrine').val();
var v_NoVacuum = $j('#NoVacuum').val();
var v_Shrinkage = v_Repack*1+v_BrokenJars*1+v_LowBrine*1+v_NoVacuum*1;
$j('#Shrinkage').val(v_Shrinkage);
}
$j('#Repack' ).on('change', update_Shrinkage);
$j('#BrokenJars' ).on('change', update_Shrinkage);
$j('#LowBrine' ).on('change', update_Shrinkage);
$j('#NoVacuum' ).on('change', update_Shrinkage);
});
Also, I attached a screenshot of my label page.
$j(function () {
$j('#Shrinkage').prop('readonly', true);
var update_Shrinkage = function () {
var v_Repack = $j('#Repack').val();
var v_BrokenJars = $j('#BrokenJars').val();
var v_LowBrine = $j('#LowBrine').val();
var v_NoVacuum = $j('#NoVacuum').val();
var v_Shrinkage = v_Repack*1+v_BrokenJars*1+v_LowBrine*1+v_NoVacuum*1;
$j('#Shrinkage').val(v_Shrinkage);
}
$j('#Repack' ).on('change', update_Shrinkage);
$j('#BrokenJars' ).on('change', update_Shrinkage);
$j('#LowBrine' ).on('change', update_Shrinkage);
$j('#NoVacuum' ).on('change', update_Shrinkage);
});
- Attachments
-
- label1.png (165.13 KiB) Viewed 2874 times
Re: Java Script Calculated and Read-Only Field
Hello, Its working now! Thank you!
I do have another question. If I wanted to make "Labeled Cases" as calculated ("Labeled Jars" divided by "Pak") and make it as read-only field as well, how do I do that?
Thanks again.
I do have another question. If I wanted to make "Labeled Cases" as calculated ("Labeled Jars" divided by "Pak") and make it as read-only field as well, how do I do that?
Thanks again.
Re: Java Script Calculated and Read-Only Field
just add
$j('#Labeled Cases').prop('readonly', true);
and in the function
var v_Labeled_Jars = $j('#Labeled Jars').val();
var v_Pak = $j('#Pak').val();
var v_Labeled_Cases=v_Labeled_Jars/v_Pak; //maybe you need to check if v_Pak is != 0 otherwise do something about it
$j('#Labeled Cases').val(v_Labeled_Cases);
$j('#Labeled Cases').prop('readonly', true);
and in the function
var v_Labeled_Jars = $j('#Labeled Jars').val();
var v_Pak = $j('#Pak').val();
var v_Labeled_Cases=v_Labeled_Jars/v_Pak; //maybe you need to check if v_Pak is != 0 otherwise do something about it
$j('#Labeled Cases').val(v_Labeled_Cases);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.