Alrighty...think I got it now. I played around with the function and came up with this:
function templateWarning(){
var dropTemplate = document.getElementById('template');
if (dropTemplate) for (var i=0; i<dropTemplate.length; i++){
if (dropTemplate[i].selected){
newTemplate = dropTemplate[i].value;
}
}
if (curTemplate == newTemplate){return;}
if (confirm('<?=$_lang['tmplvar_change_template_msg']?>')){
var redirectURL = "index.php?newtemplate=" + newTemplate + "&a=<?php echo $action; ?>";
if (<?php echo $action; ?> == 27){
redirectURL += "&id=<?php echo $id; ?>";
}
var arrElements = ["stay","pagetitle","setitle","description","alias","introtext","menuindex","parent"];
for (x=0; x<arrElements.length; x++){
elementName = document.mutate[arrElements[x]];
if(elementName.type == undefined){
elementType = elementName[0].type;
}
else{
elementType = elementName.type;
}
switch(elementType) {
case 'text':
if(elementName.value != ""){
redirectURL += "&" + elementName.name + "=" + elementName.value;
}
break;
case 'textarea':
if(elementName.value != ""){
redirectURL += "&" + elementName.name + "=" + elementName.value;
}
break;
case 'button':
if(elementName.value != ""){
redirectURL += "&" + elementName.name + "=" + elementName.value;
}
break;
case 'radio':
for (y=0; y<elementName.length; y++){
if(elementName[y].checked && elementName[y].value != ""){
redirectURL += "&" + elementName[y].name + "=" + elementName[y].value;
}
}
break;
case 'checkbox':
for (y=0; y<elementName.length; y++){
if(elementName[y].checked && elementName[y].value != ""){
redirectURL += "&" + elementName[y].name + "=" + elementName[y].value;
}
}
break;
}
}
documentDirty=false;
location.href=redirectURL;
}
else{
dropTemplate[curTemplateIndex].selected = true;
}
}
I decided just to create a simple array of the form elements to be kept. Then, test the element to ensure that the type is not undefined (this happens with checkboxes and radio buttons if you don’t use an index). Next, I used a CASE statement to select the proper type, check for empty values, then add the element onto the redirectURL variable. Pretty simple...though it does add a bit to the code.
Now all that needs to be done is to verify which form elements we wish to keep when a template is changed and mark up the form elements with GET statements. Something like this should do for most of them:
<input name="pagetitle" type="text" maxlength="100" value="<?php echo $_GET["pagetitle"] <> "" ? $_GET["pagetitle"]:htmlspecialchars(stripslashes($content['pagetitle']));?>" class="inputBox" style="width:300px;" onChange="documentDirty=true;">
This one is, of course, for the pagetitle. The only tricky one will be the Document Parent variable...it gets reset to 0 when you change the template as well...very annoying! I’ll play with the code for that one too. So far, so good....I think! If anyone knows a better, more efficient way of doing this...let me know. But at least you know where I’m going with this.
L8R!
Jeff