Connecting Tech Pros Worldwide Forums | Help | Site Map

how can a function just stop working?

Member
 
Join Date: Feb 2007
Posts: 95
#1: Sep 4 '09
I am creating a website that will allow retail insurance agents to enter enough information on a commercial truck to get a quote. I have a function called "item" that validifies the data entered into a text field. It has worked for 6 months; but, now it has quit working. However if I change the name from "item" to "bozo" it works. What gives here?

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="modelYear1" id="modelYear1" disabled="disabled" onFocus="yellowOn('modelYear1'); this.select()" onBlur="yellowOff('modelYear1'); item(1,1)" size="4" style="border: 1px solid #C0C0C0; font-family:Arial Narrow; font-size:10pt; color:#000080; font-weight:bold" maxlength="4" tabindex="2">
  2.  
  3. function item(itemCode,unitCode,optionCode){ 
  4.     var i=itemCode;
  5.     var u=unitCode;
  6.     var o=optionCode;    
  7.     /*
  8.        item 1=model
  9.        item 2=body type
  10.        item 3=GVW
  11.        item 4=make
  12.        item 5=alt make
  13.        item 6=value
  14.     */
  15.  
  16.     if(i==1){// modelYear
  17.         var modelYear;
  18.         modelYear=document.getElementById('modelYear'+u).value;
  19.         // if entry is blank
  20.         if(document.captureEvents && Event.KEYUP) { 
  21.             document.captureEvents(Event.KEYUP); 
  22.             }
  23.  
  24.         if(modelYear!=""&&modelYear!=null){
  25.             var vObject;
  26.             vObject = 'modelYear'+u; //document.getElementById('modelYear'+u).value; 
  27.             if(document.getElementById(vObject).value==""){
  28.                 //document.getElementById(vObject).style.border="1px solid #FF0000";
  29.                 document.getElementById(vObject).style.backgroundColor="#FFFFFF";
  30.  
  31.             } else {
  32.                 document.getElementById(vObject).style.border="1px solid #C0C0C0";
  33.                 document.getElementById(vObject).style.backgroundColor="#FFFFFF";
  34.             }
  35.             // if the entry does not contain only digits
  36.             if(/^\d{4}$/.test(modelYear)!=true){
  37.                 alert("You have entered an invalid year.  Please enter this vehicle's model year");
  38.                 document.getElementById('modelYear'+u).focus()
  39.                 modelYear=modelYear.replace(/^\d+$/,""); // remove all non-numeric characters
  40.             }    
  41.             // is this a valid year?    
  42.             var d=new Date();
  43.             var    thisYear=d.getYear();    
  44.             if(modelYear >thisYear+1||modelYear<=thisYear-15){
  45.                 alert("You have entered an invalid year.  Please enter this vehicle's model year");
  46.                 modelYear="";
  47.                 document.getElementById('modelYear'+u).focus()
  48.             }
  49.         }
  50.         document.getElementById('model'+u).value=modelYear;         document.getElementById('modelYear'+u).value=modelYear;
  51.     }
  52. }
There are other options; but, I have them commented out for now. This is all that's running.

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#2: Sep 4 '09

re: how can a function just stop working?


all I can think of is a name conflict (there may be another function with that name). besides that there is also a method called item() in JS.
sumittyagi's Avatar
Expert
 
Join Date: Mar 2007
Location: New Delhi, India
Posts: 198
#3: Sep 4 '09

re: how can a function just stop working?


I agree with Dormilich, I faced the same problem with another name conflict. So always use variable names that do not conflict any predefined js functions or variables.
Reply