Ok...not sure if I’m doing this correctly. This is what I have in my code:
var f = document.settings;
var evt = f.onsubmit;
f.onsubmit = function(event) {
// run your code here
var chks = f.getElementsByName('xinha_plugins_selected');
for (var i = 0; i < chks.length; i++){
if (!chks[i].checked){
chks[i].value = 'none';
}
if(evt && typeof(evt)=='function') evt(event);
}
Here’s the skinny. I have an array of checkboxes with the name xinha_plugins_selected[]. Each checkbox represents a specific plugin and the value set as the name of the plugin. The idea is that a simple array of the selected plugins is stored in the system settings for that variable. The main reason I did it like this is due to the fact that plugins will likely change and new plugins might be added.
Here’s the problem though. Once a plugin (or plugins) has been selected and the system settings are saved, the plugin is indeed selected once I go back into the configuration settings. No problem there. However, if I unselect all plugins and hit Save the new settings aren’t saved. Basically it’s a problem with the xinha_plugins_selected form array having an empty value...the script basically doesn’t see it and the current value isn’t changed in the database. So...what I understand must be done is to force the script to see the form variable and assign it a value of some sort. That’s what the script is for. It’s supposed to check to see if any checkboxes are checked and, if not, sets the value to "none". However, doesn’t appear that it’s happening.
Although I think it would be good to have a consistent way of running javascript code on form submission, there is a workaround. I can always create a hidden input value and set it to something...that way the form will always see a value for the array....but it would still be nice to have an alternative.