Solved

Auto Set Fields

Posted on 2004-09-28
7
240 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

15 Experts available now in Live!

Get 1:1 Help Now