Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 23rd, 2012, 10:25 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Odd Style Change Problem

EDIT: After pulling my head out of the forest for a bit and pouring myself a drink, I realized the problem cannot be in my code. Indeed, it must be one of the elements I am trying to access that is not hit by the first color change because it is not blank :0) Sure enough, the case was a dropdown that was not blank. I'm still not sure WHY that dropdown was giving me a problem, but I don't want to think about it right now.

************************************************** **********************************

This one has really got me puzzled.
I am doing a simple validation on a rather long form. The required field names have been put into an array which is looped through to look for blank field entries and color the background of a table cell that holds the field title.

All works fine as far as coloring the cells red. However, if the user fills in some, but not all, of the blank fields, the validation code needs to now set the title cells of the previously blank fields to white. No matter where I put the code for the white background (even directly under "Cell = document.getElementById(CellName);"), it renders the entire code useless.

The wierd stuff with the "First Element" is because the form spans two divs that are toggled (block on/off) with a tab, so if the first blank element is on page 2, it needs to focus there. If you take this code out and bare-bone it, the results are still the same.

Code:
      var Page2Key = 14;
      var Required = new Array("CompanyName","CompanyAddr","CompanyCity","CompanyState","CompanyZip","ContactName","ContactPhone","ContactEmail","PUAddress","PUCity","PUState","PUZip",      "PickupDate","DockHour","DocName","Shipper","ShipAddr","ShipCity","ShipState","ShipZip","ShipPhone","Consignee","ConsAddr","ConsCity","ConsState","ConsZip","ConsPhone");
      var x = Required.length;
      var FirstElement = "";
      var FirstElementPage = "";
      var CellName = "";
      var Cell = "";
      var P = document.PURForm;
      for(i=0;i<x;i++)
      {
         CellName = Required[i] + "Title";
         Cell = document.getElementById(CellName);
         if(P.elements[Required[i]].value == "")
         {
            if(FirstElement == "")
            {
               FirstElement = Required[i];
               if(i < Page2Key) // "DocName"
               {
                  FirstElementPage = "PUR";
               }
               else
               {
                  FirstElementPage = "DET";
               }
            }
            Cell.style.backgroundColor="#FF4A4A";
         }
         else
         {
            Cell.style.backgroundColor="#FFFFFF";
         }
      }
      if(FirstElement != "")
      {
         alert("Please enter values in the fields colored red");
         ToggleView(FirstElementPage);
         document.getElementById(FirstElement).focus();
         return false;
      }

Last edited by RationalRabbit; March 23rd, 2012 at 11:19 PM.. Reason: RESOLVED


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button Change style ran_stb ASP.NET 3.5 Professionals 1 April 14th, 2010 08:36 AM
dynamic change of style rajesh_css Javascript 3 October 10th, 2008 04:45 AM
Change Drop down Border style ismailc XSLT 2 December 10th, 2007 07:25 AM
change style.backgroundColor the reset all others crmpicco Javascript How-To 2 September 29th, 2005 09:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.