Solved

Auto Set Fields

Posted on 2004-09-28
7
241 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now