Timg
11-06-2003, 12:19 PM
Did a search for this and came up empty. Any thoughts, suggestions, and/or advice appreciated!
Currently I am in the process of redesigning our web app into an MVC compliant application (java based). I'm working on the 'view' piece at the moment (everything else is essentially done) and have come a cross what I'll term the 'Page Specific Code' issue.
My original goal was to eliminate all javascript from specific pages. For the most part this had been successful. However I've run into a stumbling block.
We have numerous places in the app where one of the following conditions are true.
1) The value of input field x directly affects the 'enablement' of another input field y either based upon the value of x (if select x has a value of a, select y enables) or a criteria such as length (if the length of text x exceeds a, text y enables).
var acctVal = document.skcs400in.in_accounta.value;
if(acctVal.length >= 9) {
document.skcs400in.in_accountb.selectedIndex = 0;
document.skcs400in.in_accountb.disabled=true;
}
else {
document.skcs400in.in_accountb.disabled=false;
}
2) The value of field x dictates whether field y is required or not. (if field x contains a, field y is required, otherwise it's not)
if (selectedValue == 'N') {
document.forms.SPTRD400in.in_new_department.required = true;
document.forms.SPTRD400in.in_cusip.required = true;
}
else {
document.forms.SPTRD400in.in_new_department.required = false;
document.forms.SPTRD400in.in_cusip.required = false;
}
3) The changing the value of field x to a specific value resets the value of field y
var rate = document.REPO100in.in_rate.value.charAt(0).toUpperCase();
if (rate == 'E') {
document.REPO100in.in_rate.value = " ";
}
These JS pieces all have to do with manipulating form fields based upon input in other form fields on the same page (without submission to the server of course).
My question is does anyone know of a good way to centralize these types functions to allow the pages themselves to be JS free (just using a .js file)?
Currently I am in the process of redesigning our web app into an MVC compliant application (java based). I'm working on the 'view' piece at the moment (everything else is essentially done) and have come a cross what I'll term the 'Page Specific Code' issue.
My original goal was to eliminate all javascript from specific pages. For the most part this had been successful. However I've run into a stumbling block.
We have numerous places in the app where one of the following conditions are true.
1) The value of input field x directly affects the 'enablement' of another input field y either based upon the value of x (if select x has a value of a, select y enables) or a criteria such as length (if the length of text x exceeds a, text y enables).
var acctVal = document.skcs400in.in_accounta.value;
if(acctVal.length >= 9) {
document.skcs400in.in_accountb.selectedIndex = 0;
document.skcs400in.in_accountb.disabled=true;
}
else {
document.skcs400in.in_accountb.disabled=false;
}
2) The value of field x dictates whether field y is required or not. (if field x contains a, field y is required, otherwise it's not)
if (selectedValue == 'N') {
document.forms.SPTRD400in.in_new_department.required = true;
document.forms.SPTRD400in.in_cusip.required = true;
}
else {
document.forms.SPTRD400in.in_new_department.required = false;
document.forms.SPTRD400in.in_cusip.required = false;
}
3) The changing the value of field x to a specific value resets the value of field y
var rate = document.REPO100in.in_rate.value.charAt(0).toUpperCase();
if (rate == 'E') {
document.REPO100in.in_rate.value = " ";
}
These JS pieces all have to do with manipulating form fields based upon input in other form fields on the same page (without submission to the server of course).
My question is does anyone know of a good way to centralize these types functions to allow the pages themselves to be JS free (just using a .js file)?