Solved

Auto Set Fields

Posted on 2004-09-28
7
244 Views
Last Modified: 2010-04-17
Objective: if Corporate Name is entered as Regency Holdings, associated fields get auto filled...if Corporate Name does not equal Regency Holdings, fields await input...I have the following code:

<script language="JavaScript">
function Regency() {
if (document.forms[0].CndnOwnFirstName.value="Regency Holdings")
document.forms[0].CndnOwnStreet.value="3rd Flr Trade Winds Bldng";
document.forms[0].CndnOwnCity.value="Nassau";
document.forms[0].CndnOwnStProv.value="New Providence";
document.forms[0].CndnOwnZipPC.value="P.O. Box CB-12724";
document.forms[0].CndnOwnCountry.value="The Bahama Islands";
document.forms[0].CndnOwnHomePhone.value="242-326-5205";
document.forms[0].CndnOwnRel.value="Nominee";
}
else if (document.forms[0].CndnOwnFirstName.value=="Regency Holdings")
document.forms[0].CndnOwnStreet.value="";
document.forms[0].CndnOwnCity.value="";
document.forms[0].CndnOwnStProv.value="";
document.forms[0].CndnOwnZipPC.value="";
document.forms[0].CndnOwnCountry.value="";
document.forms[0].CndnOwnHomePhone.value="";
document.forms[0].CndnOwnRel.value="";
}  
</script>

Doesn't work...suggestions please.

Thanks,
Ron
0
Comment
Question by:ronaldj
  • 6
7 Comments
 

Author Comment

by:ronaldj
ID: 12170063
PS... event is triggered by the following:

<input type="text" name="CndnOwnFirstName"  value="$CndnOwnFirstName$" onblur="Regency()" onkeypress="return handleEnter(this, event)" size="20" style="text-transform: capitalize; font-family:Arial; font-size:10pt"; font-family:Arial; font-size:10pt"></font></td>
     
Ron
0
 

Author Comment

by:ronaldj
ID: 12171215
OK...in trying to decipher this problem myself, I shortened the code to look like the following:

<script language="JavaScript">
function Regency() {
if (document.forms[0].CndnOwnFirstName.value="Regency Holdings")  
alert("RH Yes");
document.forms[0].CndnOwnStreet.value="3rd Flr Trade Winds Bldng";
document.forms[0].CndnOwnCity.value="Nassau";
document.forms[0].CndnOwnStProv.value="New Providence";
document.forms[0].CndnOwnZipPC.value="P.O. Box CB-12724";
document.forms[0].CndnOwnCountry.value="The Bahama Islands";
document.forms[0].CndnOwnHomePhone.value="242-326-5205";
document.forms[0].CndnOwnRel.value="Nominee";
}
</script>

with the alert inserted figured an easy way to trace...If I type in Regency Holdings, everything flows just fine...HOWEVER, if I type in XYZ Corp, as soon as I loose focus (onblur event) you can see in the background XYZ Corp is changed to Regency Holdings and the alert statement comes up...Soo, somehow in the code above the field CndnOwnFirstName is getting reset to Regency...Does this help any?

Thanks,
Ron
0
 
LVL 4

Accepted Solution

by:
avi247 earned 125 total points
ID: 12171285
Read: http://www.echoecho.com/javascript6.htm

If we wrote browser="MSIE" we would actually store "MSIE" in the variable called browser.
When you write browser=="MSIE" javascript knows that you want it to compare rather than assign a value.

SO, this statement
(document.forms[0].CndnOwnFirstName.value="Regency Holdings")

is actually assigning (and not comparing). That is why you see XYZ Corp getting changed to Regency Holdings.

Do this.
function Regency() {
     if (document.forms[0].CndnOwnFirstName.value=="Regency Holdings") {
      alert("RH Yes");
      document.forms[0].CndnOwnStreet.value="3rd Flr Trade Winds Bldng";
      document.forms[0].CndnOwnCity.value="Nassau";
      document.forms[0].CndnOwnStProv.value="New Providence";
      document.forms[0].CndnOwnZipPC.value="P.O. Box CB-12724";
      document.forms[0].CndnOwnCountry.value="The Bahama Islands";
      document.forms[0].CndnOwnHomePhone.value="242-326-5205";
      document.forms[0].CndnOwnRel.value="Nominee";
     }else{
         lert("RH No");
      document.forms[0].CndnOwnStreet.value="";
      document.forms[0].CndnOwnCity.value="";
      document.forms[0].CndnOwnStProv.value="";
      document.forms[0].CndnOwnZipPC.value="";
      document.forms[0].CndnOwnCountry.value="";
      document.forms[0].CndnOwnHomePhone.value="";
      document.forms[0].CndnOwnRel.value="";

     }      
}


0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ronaldj
ID: 12171863
Almost thought we were there!...still am having the problem if I type in, e.g., XYZ Corp, field gets changed to Regency Holdings...my adjusted code is as follows:

<script language="JavaScript">
function Regency() {
if (document.forms[0].CndnOwnFirstName.value="Regency Holdings"){  
alert("RH Yes");
document.forms[0].CndnOwnStreet.value="3rd Flr Trade Winds Bldng";
document.forms[0].CndnOwnCity.value="Nassau";
document.forms[0].CndnOwnStProv.value="New Providence";
document.forms[0].CndnOwnZipPC.value="P.O. Box CB-12724";
document.forms[0].CndnOwnCountry.value="The Bahama Islands";
document.forms[0].CndnOwnHomePhone.value="242-326-5205";
document.forms[0].CndnOwnRel.value="Nominee";
}else
if (document.forms[0].CndnOwnFirstName.value!="Regency Holdings"){
alert("RH No");
document.forms[0].CndnOwnStreet.value="";
document.forms[0].CndnOwnCity.value="";
document.forms[0].CndnOwnStProv.value="";
document.forms[0].CndnOwnZipPC.value="";
document.forms[0].CndnOwnCountry.value="";
document.forms[0].CndnOwnHomePhone.value="";
document.forms[0].CndnOwnRel.value="";
}
  }
</script>

Thoughts? Thanks for the input!

Ron
0
 

Author Comment

by:ronaldj
ID: 12171973
Don't know if this helps but if I type in XYZ Corp, alert comes back as "RH Yes"...would have expected "RH No"...??? since XYZ Corp <> Regency Holdings...

Ron
0
 

Author Comment

by:ronaldj
ID: 12172129
OK, this is VERY bizzare...with your suggested code, if I type in "Regency Holdings", alert NO gets triggered...Boo...if I do a copy/paste of the text "Regency Holdings" from code into field, everything works!!! Perplexed...

Ron
0
 

Author Comment

by:ronaldj
ID: 12172331
Perplexed has found the solution!...way back in my Q/A I refered to the input line

onkeypress="return handleEnter(this, event)"

this routine turns the first letters of the input line text into capitals...so what I viewed as being "Regency Holdings" was in fact, computer wise, "regency holdings"...if I type in with "shift" the r & h of the 2 words, works just fine...probably, if possible, put in a if/or for "regency holdings" vs Regency Holdings in the JS routine...

Thanks for all your help.

Ron
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question