Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.