Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make fields readonly based on input from another field

Status
Not open for further replies.

Jawa

Programmer
Feb 21, 2002
74
US
If someone could help out here I would appreciate it.

I would like to use JS so that when you enter in a specific value into an input box it can instruct the 3 input boxes below it to be readonly or not.

Basically what I have is a JS that auto fills in city and state based on a zip code and keeps the fields readonly, but if the zip code does not match I want the fields to enable the user to type in the city and state.

Thank you!!!!
 
Code:
zipArr = new Array("12345","67890","12121","90909")
cityArr = new Array("City1","City2","City3","City4")
stateArr = new Array("OK","OH","IL","TX")

function checkZip(){
  boolFound = false
  inZip = document.myForm.zip.value
  for (x=0; x<zipArr.length; x++){
    if (zipArr[x] == inZip){
      document.myForm.city.value = cityArr[x]
      document.myForm.city.readOnly = true
      document.myForm.state.value = stateArr[x]
      document.myForm.state.readOnly = true
      boolFound = true
      break;
    }
  }
  if (!boolFound){
    document.myForm.city.readOnly = false
    document.myForm.state.readOnly = false
  }
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
This did the trick perfectly!!!!!! THANK YOU!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top