Solved

Auto Set Fields

Posted on 2004-09-28
7
245 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 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