- Lead Form OnChange event jscript ot Working need expert advice
- Posted by Dan white on September 8th, 2006
I created the following Jscript in the lead form onchange in zipcode, However
it doesnt seem to work, Please look at it and give me some advice.
What this Script is suppose to do, is when you put a ZipCode in thtas in the
array, it and move to the next field, it should automatically populate the
Address1_County Attribute, But it doesnt.
Please HELP.. Thanks
I have hit a Brick wall moving at 100 miles an hour, without a Helmet!
crmForm.all.address1_postalcode.DataValue
{
var info = new Array(192);
info[0]="NW Palm Beach";
info[1]="33478";
info[2]="33418";
info[3]="33412";
info[4]="33411";
info[5]="NE Palm Beach";
info[6]="33458";
info[7]="33469";
info[8]="33477";
info[9]="33410";
info[10]="33408";
info[11]="33403";
info[12]="33404";
info[13]="33407";
info[14]="33401";
info[15]="33417";
info[16]="33409";
info[17]="33413";
info[18]="33480";
info[19]="Central Palm Beach";
info[20]="33414";
info[21]="33467";
info[22]="33415";
info[23]="33406";
info[24]="33405";
info[25]="33461";
info[26]="33460";
info[27]="33480";
info[28]="33463";
info[29]="33462";
info[30]="33436";
info[31]="SW Palm Beach";
info[32]="33437";
info[33]="33484";
info[34]="33446";
info[35]="33496";
info[36]="33498";
info[37]="33434";
info[38]="33428";
info[39]="33433";
info[40]="SE Palm Beach";
info[41]="33426";
info[42]="33437";
info[43]="33435";
info[44]="33436";
info[45]="33445";
info[46]="33444";
info[47]="33483";
info[48]="33487";
info[49]="33431";
info[50]="33486";
info[51]="33432";
info[52]="NW Broward";
info[53]="33076";
info[54]="33067";
info[55]="33065";
info[56]="33073";
info[57]="33071";
info[58]="33063";
info[59]="33066";
info[60]="33066";
info[61]="33068";
info[62]="33321";
info[63]="NE Broward";
info[64]="33442";
info[65]="33441";
info[66]="33073";
info[67]="33062";
info[68]="33064";
info[69]="33060";
info[70]="33062";
info[71]="33069";
info[72]="Central West Broward";
info[73]="33351";
info[74]="33319";
info[75]="33322";
info[76]="33313";
info[77]="33323";
info[78]="33324";
info[79]="33317";
info[80]="Central East Broward";
info[81]="33309";
info[82]="33334";
info[83]="33308";
info[84]="33311";
info[85]="33305";
info[86]="33304";
info[87]="33301";
info[88]="33312";
info[89]="33315";
info[90]="33316";
info[91]="33019";
info[92]="SW Broward";
info[93]="33327";
info[94]="33326";
info[95]="33325";
info[96]="33332";
info[97]="33330";
info[98]="33328";
info[99]="33331";
info[100]="33026";
info[101]="33028";
info[102]="33024";
info[103]="33029";
info[104]="33027";
info[105]="33025";
info[106]="SE Broward";
info[107]="33314";
info[108]="33004";
info[109]="33029";
info[110]="33024";
info[111]="33020";
info[112]="33019";
info[113]="33023";
info[114]="33009";
info[115]="NW Dade";
info[116]="33018";
info[117]="33015";
info[118]="33059";
info[119]="33056";
info[120]="33016";
info[121]="33054";
info[122]="33014";
info[123]="33012";
info[124]="33018";
info[125]="33167";
info[126]="33013";
info[127]="33147";
info[128]="33010";
info[129]="33142";
info[130]="33178";
info[131]="33160";
info[132]="33172";
info[133]="33122";
info[134]="33125";
info[135]="NE Dade";
info[136]="33179";
info[137]="33180";
info[138]="33169";
info[139]="33162";
info[140]="33160";
info[141]="33161";
info[142]="33181";
info[143]="33154";
info[144]="33138";
info[145]="33141";
info[146]="33140";
info[147]="33137";
info[148]="33139";
info[149]="Central West Dade";
info[150]="33129";
info[151]="33182";
info[152]="33194";
info[153]="33184";
info[154]="33185";
info[155]="33175";
info[156]="33193";
info[157]="33183";
info[158]="33186";
info[159]="33196";
info[160]="33187";
info[161]="33177";
info[162]="Central East Dade";
info[163]="33174";
info[164]="33126";
info[165]="33135";
info[166]="33128";
info[167]="33132";
info[168]="33131";
info[169]="33109";
info[170]="33129";
info[171]="33165";
info[172]="33155";
info[173]="33134";
info[174]="33145";
info[175]="33173";
info[176]="33143";
info[177]="33176";
info[178]="33156";
info[179]="33176";
info[180]="33158";
info[181]="33149";
info[182]="South Dade";
info[183]="33157";
info[184]="33189";
info[185]="33190";
info[186]="33170";
info[187]="33031";
info[188]="33032";
info[189]="33030";
info[190]="33033";
info[191]="33039";
info[192]="33033";
function getIndex(address1_postalcode) { for (i=0;i<192;i++) {
if (info[i] == address1_postalcode) {
return i;
}
}
return -1;
}
function isDigit(num) {
if (num.length > 1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;} return false; }
function getCounty(zipIndex) {
for (i=zipIndex-1;i>=0;i--) {
if (!isDigit(info[i].charAt(0))) {
return info[i];
}
}
return "NOT FOUND";
}
function update() {
var address1_postalcode = crmForm.all.address1_postalcode.DataValue;
var zipIndex = getIndex(zipcode);
if (zipIndex == -1) {
alert("No such zipcode found");
} else {
county = getCounty(zipIndex);
crmForm.all.address1_county.DataValue= county; }
- Posted by Michael Höhne on September 8th, 2006
Without having looked into your code in detail, there's one thing that
definitely causes problems:
function getIndex(address1_postalcode) { for (i=0;i<192;i++) {
if (info[i] == address1_postalcode) {
return i;
}
}
return -1;
}
if (info[i] == address1_postalcode) {
should be
if (info[i] == address1_postalcode.DataValue) {
Otherwise, the function will always return -1.
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
"Dan white" <Danwhite@discussions.microsoft.com> schrieb im Newsbeitrag
news:F6778DDF-AE7D-453E-BB47-9E7C6559D839@microsoft.com...
- Posted by Michael Höhne on September 8th, 2006
Please discard my last response. Overlooked that you passed
address1_postalcode as a parameter.
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
"Michael Höhne" <michael.hoehne@nospam.nospam> schrieb im Newsbeitrag
news:e1ox9O50GHA.4796@TK2MSFTNGP03.phx.gbl...
- Posted by Michael Höhne on September 8th, 2006
Where does your code start?
crmForm.all.address1_postalcode.DataValue
{
var info = new Array(192);
This doesn't look like a valid statement. Is all of that included in
global.js and you're calling it from the onChange event? I don't see any way
to test your code?
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
"Dan white" <Danwhite@discussions.microsoft.com> schrieb im Newsbeitrag
news:F6778DDF-AE7D-453E-BB47-9E7C6559D839@microsoft.com...
- Posted by Dan white on September 9th, 2006
Take the following code and save it to an HTML file, It works fine. I just
want it to work in CRM
<html>
<script language="javascript">
var info = new Array(192);
info[0]="NW Palm Beach";
info[1]="33478";
info[2]="33418";
info[3]="33412";
info[4]="33411";
info[5]="NE Palm Beach";
info[6]="33458";
info[7]="33469";
info[8]="33477";
info[9]="33410";
info[10]="33408";
info[11]="33403";
info[12]="33404";
info[13]="33407";
info[14]="33401";
info[15]="33417";
info[16]="33409";
info[17]="33413";
info[18]="33480";
info[19]="Central Palm Beach";
info[20]="33414";
info[21]="33467";
info[22]="33415";
info[23]="33406";
info[24]="33405";
info[25]="33461";
info[26]="33460";
info[27]="33480";
info[28]="33463";
info[29]="33462";
info[30]="33436";
info[31]="SW Palm Beach";
info[32]="33437";
info[33]="33484";
info[34]="33446";
info[35]="33496";
info[36]="33498";
info[37]="33434";
info[38]="33428";
info[39]="33433";
info[40]="SE Palm Beach";
info[41]="33426";
info[42]="33437";
info[43]="33435";
info[44]="33436";
info[45]="33445";
info[46]="33444";
info[47]="33483";
info[48]="33487";
info[49]="33431";
info[50]="33486";
info[51]="33432";
info[52]="NW Broward";
info[53]="33076";
info[54]="33067";
info[55]="33065";
info[56]="33073";
info[57]="33071";
info[58]="33063";
info[59]="33066";
info[60]="33066";
info[61]="33068";
info[62]="33321";
info[63]="NE Broward";
info[64]="33442";
info[65]="33441";
info[66]="33073";
info[67]="33062";
info[68]="33064";
info[69]="33060";
info[70]="33062";
info[71]="33069";
info[72]="Central West Broward";
info[73]="33351";
info[74]="33319";
info[75]="33322";
info[76]="33313";
info[77]="33323";
info[78]="33324";
info[79]="33317";
info[80]="Central East Broward";
info[81]="33309";
info[82]="33334";
info[83]="33308";
info[84]="33311";
info[85]="33305";
info[86]="33304";
info[87]="33301";
info[88]="33312";
info[89]="33315";
info[90]="33316";
info[91]="33019";
info[92]="SW Broward";
info[93]="33327";
info[94]="33326";
info[95]="33325";
info[96]="33332";
info[97]="33330";
info[98]="33328";
info[99]="33331";
info[100]="33026";
info[101]="33028";
info[102]="33024";
info[103]="33029";
info[104]="33027";
info[105]="33025";
info[106]="SE Broward";
info[107]="33314";
info[108]="33004";
info[109]="33029";
info[110]="33024";
info[111]="33020";
info[112]="33019";
info[113]="33023";
info[114]="33009";
info[115]="NW Dade";
info[116]="33018";
info[117]="33015";
info[118]="33059";
info[119]="33056";
info[120]="33016";
info[121]="33054";
info[122]="33014";
info[123]="33012";
info[124]="33018";
info[125]="33167";
info[126]="33013";
info[127]="33147";
info[128]="33010";
info[129]="33142";
info[130]="33178";
info[131]="33160";
info[132]="33172";
info[133]="33122";
info[134]="33125";
info[135]="NE Dade";
info[136]="33179";
info[137]="33180";
info[138]="33169";
info[139]="33162";
info[140]="33160";
info[141]="33161";
info[142]="33181";
info[143]="33154";
info[144]="33138";
info[145]="33141";
info[146]="33140";
info[147]="33137";
info[148]="33139";
info[149]="Central West Dade";
info[150]="33129";
info[151]="33182";
info[152]="33194";
info[153]="33184";
info[154]="33185";
info[155]="33175";
info[156]="33193";
info[157]="33183";
info[158]="33186";
info[159]="33196";
info[160]="33187";
info[161]="33177";
info[162]="Central East Dade";
info[163]="33174";
info[164]="33126";
info[165]="33135";
info[166]="33128";
info[167]="33132";
info[168]="33131";
info[169]="33109";
info[170]="33129";
info[171]="33165";
info[172]="33155";
info[173]="33134";
info[174]="33145";
info[175]="33173";
info[176]="33143";
info[177]="33176";
info[178]="33156";
info[179]="33176";
info[180]="33158";
info[181]="33149";
info[182]="South Dade";
info[183]="33157";
info[184]="33189";
info[185]="33190";
info[186]="33170";
info[187]="33031";
info[188]="33032";
info[189]="33030";
info[190]="33033";
info[191]="33039";
info[192]="33033";
function getIndex(zipcode) {
for (i=0;i<192;i++) {
if (info[i] == zipcode) {
return i;
}
}
return -1;
}
function isDigit(num) {
if (num.length > 1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}
function getCounty(zipIndex) {
for (i=zipIndex-1;i>=0;i--) {
if (!isDigit(info[i].charAt(0))) {
return info[i];
}
}
return "NOT FOUND";
}
function update() {
var zipcode = document.theform.zipcode.value;
var zipIndex = getIndex(zipcode);
if (zipIndex == -1) {
alert("No such zipcode found");
} else {
county = getCounty(zipIndex);
document.theform.county.value = county;
}
}
</script>
<body>
<form name="theform">
<table>
<tr>
<td>
Zip Code:
</td>
<td>
<input type="text" name="zipcode" value="" onchange="update();">
</td>
<tr>
<td>
County:
</td>
<td>
<input type="text" name="county" value="">
</td>
<tr>
</form>
</body>
"Michael Höhne" wrote:
- Posted by Michael Höhne on September 9th, 2006
I rewrote the script to not contain any functions. You can use it in the
OnChange event of the address1_postalcode field. It may not be the best way
to do it, but it doesn't need any modificatons to server files (global.js)
and will also work offline.
var info = new Array(192);
info[0]="NW Palm Beach";
info[1]="33478";
info[2]="33418";
info[3]="33412";
info[4]="33411";
info[5]="NE Palm Beach";
info[6]="33458";
info[7]="33469";
info[8]="33477";
info[9]="33410";
info[10]="33408";
info[11]="33403";
info[12]="33404";
info[13]="33407";
info[14]="33401";
info[15]="33417";
info[16]="33409";
info[17]="33413";
info[18]="33480";
info[19]="Central Palm Beach";
info[20]="33414";
info[21]="33467";
info[22]="33415";
info[23]="33406";
info[24]="33405";
info[25]="33461";
info[26]="33460";
info[27]="33480";
info[28]="33463";
info[29]="33462";
info[30]="33436";
info[31]="SW Palm Beach";
info[32]="33437";
info[33]="33484";
info[34]="33446";
info[35]="33496";
info[36]="33498";
info[37]="33434";
info[38]="33428";
info[39]="33433";
info[40]="SE Palm Beach";
info[41]="33426";
info[42]="33437";
info[43]="33435";
info[44]="33436";
info[45]="33445";
info[46]="33444";
info[47]="33483";
info[48]="33487";
info[49]="33431";
info[50]="33486";
info[51]="33432";
info[52]="NW Broward";
info[53]="33076";
info[54]="33067";
info[55]="33065";
info[56]="33073";
info[57]="33071";
info[58]="33063";
info[59]="33066";
info[60]="33066";
info[61]="33068";
info[62]="33321";
info[63]="NE Broward";
info[64]="33442";
info[65]="33441";
info[66]="33073";
info[67]="33062";
info[68]="33064";
info[69]="33060";
info[70]="33062";
info[71]="33069";
info[72]="Central West Broward";
info[73]="33351";
info[74]="33319";
info[75]="33322";
info[76]="33313";
info[77]="33323";
info[78]="33324";
info[79]="33317";
info[80]="Central East Broward";
info[81]="33309";
info[82]="33334";
info[83]="33308";
info[84]="33311";
info[85]="33305";
info[86]="33304";
info[87]="33301";
info[88]="33312";
info[89]="33315";
info[90]="33316";
info[91]="33019";
info[92]="SW Broward";
info[93]="33327";
info[94]="33326";
info[95]="33325";
info[96]="33332";
info[97]="33330";
info[98]="33328";
info[99]="33331";
info[100]="33026";
info[101]="33028";
info[102]="33024";
info[103]="33029";
info[104]="33027";
info[105]="33025";
info[106]="SE Broward";
info[107]="33314";
info[108]="33004";
info[109]="33029";
info[110]="33024";
info[111]="33020";
info[112]="33019";
info[113]="33023";
info[114]="33009";
info[115]="NW Dade";
info[116]="33018";
info[117]="33015";
info[118]="33059";
info[119]="33056";
info[120]="33016";
info[121]="33054";
info[122]="33014";
info[123]="33012";
info[124]="33018";
info[125]="33167";
info[126]="33013";
info[127]="33147";
info[128]="33010";
info[129]="33142";
info[130]="33178";
info[131]="33160";
info[132]="33172";
info[133]="33122";
info[134]="33125";
info[135]="NE Dade";
info[136]="33179";
info[137]="33180";
info[138]="33169";
info[139]="33162";
info[140]="33160";
info[141]="33161";
info[142]="33181";
info[143]="33154";
info[144]="33138";
info[145]="33141";
info[146]="33140";
info[147]="33137";
info[148]="33139";
info[149]="Central West Dade";
info[150]="33129";
info[151]="33182";
info[152]="33194";
info[153]="33184";
info[154]="33185";
info[155]="33175";
info[156]="33193";
info[157]="33183";
info[158]="33186";
info[159]="33196";
info[160]="33187";
info[161]="33177";
info[162]="Central East Dade";
info[163]="33174";
info[164]="33126";
info[165]="33135";
info[166]="33128";
info[167]="33132";
info[168]="33131";
info[169]="33109";
info[170]="33129";
info[171]="33165";
info[172]="33155";
info[173]="33134";
info[174]="33145";
info[175]="33173";
info[176]="33143";
info[177]="33176";
info[178]="33156";
info[179]="33176";
info[180]="33158";
info[181]="33149";
info[182]="South Dade";
info[183]="33157";
info[184]="33189";
info[185]="33190";
info[186]="33170";
info[187]="33031";
info[188]="33032";
info[189]="33030";
info[190]="33033";
info[191]="33039";
info[192]="33033";
var zipcode = crmForm.all.address1_postalcode.DataValue;
if (zipcode == null) {
crmForm.all.address1_county.DataValue = null;
return;
}
var zipIndex = -1;
for (i = 0; i < 192; i++) {
if (info[i] == zipcode) {
zipIndex = i;
break;
}
}
if (zipIndex == -1) {
alert("No such zipcode found");
}
else {
var county = "NOT FOUND";
for (i = zipIndex-1; i >=0; i--) {
if (isNaN(info[i])) {
county = info[i];
break;
}
}
crmForm.all.address1_county.DataValue = county;
}
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
"Dan white" <Danwhite@discussions.microsoft.com> schrieb im Newsbeitrag
news:E8656476-0501-47CD-8A6F-E15BBEAD430B@microsoft.com...