Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto Set Fields

Posted on 2004-09-28
7
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

721 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