robdawg777
04-19-2005, 09:42 PM
I have a script that I use for a site where people can creat custom brochures and things like that. This script is used to hide form fields. A guy I work with wrote it and while I am working learn javascript and can edit this script for the purposes that I need it for I have realized that it is not cross-browser compatible. For some reason it works in all browsers I have tested except Safari. If someone could look it over and maybe give me a snippet of code that would do the same thing, but work across all browers, just enough to point me in the right direction that would be much appreciated.
Here's the script:
//This function is called only in EDIT mode and when the dropdown list changes.
//Show appropriate fileds depending on dropdown selection.
function DocumentTypeFields(){
var docType = document.forms[0].elements["FIELD_" + FieldIDs["Pictures_Text"]];
if (docType.options[docType.selectedIndex].value == "")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "PlayWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "RuggedWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "SunsetWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "PlayAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "RuggedAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "SunsetAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
}
if (PFFormMode == "EDIT")
{
var docType = document.forms[0].elements["FIELD_" + FieldIDs["Pictures_Text"]];
if (docType != null)
{
//alert("not null");
docType.onchange = new Function("e", "DocumentTypeFields();");
DocumentTypeFields();
}
}
else if (PFFormMode == "VIEW")
{
if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "SunsetWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "RuggedWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "PlayWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "SunsetAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "RuggedAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "PlayAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
}
BTW, This script is written the way it is because this is something I am putting into an aspx page where there's not a way to get directly into all the code so the script has to grab the ID's on the page to hide them as needed depending on the selections made by the user.
Thanks
Here's the script:
//This function is called only in EDIT mode and when the dropdown list changes.
//Show appropriate fileds depending on dropdown selection.
function DocumentTypeFields(){
var docType = document.forms[0].elements["FIELD_" + FieldIDs["Pictures_Text"]];
if (docType.options[docType.selectedIndex].value == "")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "PlayWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "RuggedWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "SunsetWCopy")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "block";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "block";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "block";
}
else if (docType.options[docType.selectedIndex].value == "PlayAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "RuggedAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
else if (docType.options[docType.selectedIndex].value == "SunsetAllPics")
{
document.all["LABEL_" + FieldIDs["Headline"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Headline"]].style.display = "none";
document.all["LABEL_" + FieldIDs["Copy"]].style.display = "none";
document.all["VALUE_" + FieldIDs["Copy"]].style.display = "none";
}
}
if (PFFormMode == "EDIT")
{
var docType = document.forms[0].elements["FIELD_" + FieldIDs["Pictures_Text"]];
if (docType != null)
{
//alert("not null");
docType.onchange = new Function("e", "DocumentTypeFields();");
DocumentTypeFields();
}
}
else if (PFFormMode == "VIEW")
{
if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "SunsetWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "RuggedWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "PlayWCopy")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "block";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "block";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "SunsetAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "RuggedAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
else if (document.all["VALUE_" + FieldIDs["Pictures_Text"]].innerHTML == "PlayAllPics")
{
document.all["ROW__" + FieldIDs["Headline"]].style.display = "none";
document.all["ROW_" + FieldIDs["Copy"]].style.display = "none";
}
}
BTW, This script is written the way it is because this is something I am putting into an aspx page where there's not a way to get directly into all the code so the script has to grab the ID's on the page to hide them as needed depending on the selections made by the user.
Thanks