/    Sign up×
Community /Pin to ProfileBookmark

page reload script problem

The code works. But sometimes when my php validation echos and error to the user and then the user resubmits the data the state and city will not be put in the database.

If the user doesn’t return an error on the first submit then the state and city are updated with the ones the user selected. How do I fix this?

[CODE]<script type=”text/javascript”>
// For:

STATES = [“Alabama|Abbeville|Andalusia|Anniston|Athens|Cullman|Decatur|Birmingham|Florence|Fort Payne|Gadsden|Huntsville|Jasper|Madison|Mobile|Montgomery|Phenix City|Prattville|Russellville|Selma|Talladega|Tuscaloosa|Tuskegee”,
“Alaska|Acnhorage|Fairbanks|Juneau|Sitka|Wasilla”,
“Arizona|Avondale|Buckeye|Bullhead City|Casa Grande|Chandler|Douglas|El Mirage|Flagstaff|Gilbert|Goodyear|Kingman|Lake Havasu City|Maricopa|Mesa|Nogales|Phoenix|Prescott|Surprise|Tempe|Tucson|Winslow|Yuma”,
“Arkansas|Arkadelphia|Bella Vista|Benton|Bentonville|Blytheville|Cabot|Camden|Conway|El Dorado|Fayetteville|Fort Smith|Forrest City|Harrison|Hot Springs|Hope|Jacksonville|Jonesboro|Little Rock|Magnolia|Maumelle|Mountain Home|North Little Rock|Paragould|Pine Bluff|Rogers|Russellville|Searcy|Sherwood|Siloam Springs|Springdale|Texarkana|Van Buren|West Memphis”,
“California|Anaheim|Bakersfield|Chula Vista|Fremont|Fresno|Fontana|Garden Grove|Glendale|Huntington Beach|Irvine|Lompoc|Long Beach|Los Angeles|Modesto|Moreno Valley|Oakland|Oceanside|Ontario|Oxnard|Pomona|Rancho Cucamonga|Riverside|Sacramento|San Diego|San Bernardino|San Francisco|San Jose|Santa Ana|Santa Clarita|Santa Rosa|Stockton”, “Colorado|Arvada|Aurora|Boulder|Broomfield|Castlewood|Colorado Springs|Columbine|Denver|Englewood|Fort Collins|Grand Junction|Greeley|Highlands Ranch|Ken Caryl|Lakewood|Littleton|Longmont|Loveland|Northglenn|Pueblo|Security-Widefield|Southglenn|Thornton|Westminster|Wheat Ridge”, “Connecticut|Bridgeport|Bristol|Central Manchester|Danbury|East Hartford|West Hartford|Hartford|East Haven|West Haven|New Haven|Meriden|Middletown|Milford|Naugatuck|Newington|New Britain|Norwalk|Norwich|Stamford|Stratford|Shelton|Torrington|Trumbull|Waterbury|Wethersfield”,
“Delaware|Delaware City|Dover|Elsmere|Middletown|Georgetown|Harrington|Laurel|Lewes|Milford|Newark|New Castle|Rehoboth Beach|Seaford|Wilmington”,
“Florida|Boynton Beach|Clearwater|Deltona|Ft. Lauderdale|Ft. Meyers|Gainesville|Hollywood|Homestead|Jacksonville|Jupiter|Key Largo|Miami|North Miami|South Miami|Naples|Orlando|Ocala|Palm Beach|West Palm Beach|Panama City|Pensacola|St. Petersburg|Spring Hill|Tallahassee|Tampa”,
“Georgia|Albany|Alpharetta|Atlanta|Athens-Clarke|Augusta-Richmond|Candler-McAfee|Columbus|Dalton|Dunwoody|East Point|Hinesville|Mableton|Macon|Marietta|Martinez|North Atlanta|Peachtree City|Redan|Rome|Roswell|Sandy Springs|Savannah|Smyrna|Warner Robins|Valdosta”,
“Hawaii|Ewa Beach|Halawa|Hilo|Honolulu|Kailua|Kaneohe|Kaneohe Station|Kihei|Makakilo City|Mililani Town|Nanakuli|Pearl City|Schofield Barracks|Wahiawa|Waianae|Wailuku|Waimalu|Waipahu|Waipio”,
“Idaho|Ammon|Blackfoot|Boise|Burley|Caldwell|Chubbuck|Coeur d’Alene|Eagle|Garden City|Hailey|Hayden|Idaho Falls|Jerome|Lewiston|Meridian|Moscow|Mountain Home|Mountain Home AFB|Nampa|Payette|Pocatello|Post Falls|Rexburg|Sandpoint|Twin Falls”,
“Illinois|Rockford|Arlington Heights|Aurora|Berwyn|Bloomington|Bolingbrook|Champaign|Chicago|Cicero|Decatur|Des Plaines|Elgin|Evanston|Joliet|Mount Prospect|Naperville|Oak Lawn|Oak Park|Palatine|Peoria|Schaumburg|Skokie|Springfield|Waukegan|Wheaton”,
“Indiana|Anderson|Bloomington Muncie|Carmel|Columbus|East Chicago|Elkhart|Evansville|Fishers|Fort Wayne|Gary|Greenwood|Hammond|Indianapolis|Kokomo|Lafayette|Lawrence|Marion|Michigan City|Mishawaka|New Albany|Portage|Richmond|South Bend|Terre Haute”,
“Iowa|Ankeny|Ames|Bettendorf|Burlington|Cedar Falls|Cedar Rapids|Clinton|Council Bluffs|Davenport|Des Moines|Dubuque|Fort Dodge|Iowa City|Marion|Marshalltown|Mason City|Muscatine|Newton|Ottumwa|Sioux City|Urbandale|Waterloo|West Des Moines”,
“Kansas|Derby|Dodge City|Emporia|Garden City|Great Bend|Hays|Hutchinson|Junction City|Kansas City|Lawrence|Leawood|Leavenworth|Lenexa|Liberal|Manhattan|McPherson|Newton|Olathe|Overland Park|Pittsburg|Prairie Village|Salina|Shawnee|Topeka|Wichita|Winfield”,
“Kentucky|Ashland|Bowling Green|Covington|Elizabethtown|Fern Creek|Frankfort|Florence|Georgetown|Henderson|Hopkinsville|Jeffersontown|Lexington-Fayette|Louisville|Madisonville|Newburg|Owensboro|Paducah|Pleasure Ridge Park|Radcliff|Richmond|Nicholasville|Valley Station”,
“Louisiana|Alexandria|Baton Rouge|Bayou Cane|Bossier City|Chalmette|Gretna|Hammond|Harvey|Houma|Kenner|Lake Charles|Lafayette|Laplace|Marrero|Metairie|Monroe|Natchitoches|New Iberia|New Orleans|Opelousas|Ruston|Shreveport|Slidell|Shenandoah|Sulphur|Terrytown”,
“Maine|Auburn|Augusta|Bangor|Biddeford|Brunswick|Lewiston|Portland|Saco|South Portland|Waterville|Westbrook”,
“Maryland|Annapolis|Aspen Hill|Baltimore|Bel Air South|Bethesda|North Bethesda|Bowie|Catonsville|Columbia|Dundalk|Ellicott City|Essex|Frederick|Gaithersburg|Germantown|Glen Burnie|Potomac|Rockville|Silver Spring|Towson|Wheaton-Glenmont”,
“Massachusetts|Brockton|Brookline|Boston|Cambridge|Chicopee|Fall River|Framingham|Haverhill|Lawrence|Lynn|Lowell|Malden|Medford|Newton|New Bedford|Quincy|Somerville|Springfield|Taunton|Waltham|Worcester “,
“Michigan|Ann Arbor|Canton|Clinton|Dearborn|Detroit|Farmington Hills|Flint|Grand Rapids|Kalamazoo|Lansing|Livonia |Pontiac|Rochester Hills|Saginaw|Shelby|Southfield|St. Clair Shores|Sterling Heights|Taylor|Troy|Warren|Waterford|WestlandWyoming”,
“Oregon|Albany|Aloha|Beaverton|Bend|Corvallis|Eugene|Gresham|Hillsboro|Keizer|Lake Oswego|McMinnville|Medford|Oregon City|Portland|Salem|Springfield|Tigard”,
“Pennsylvania|Allentown|Altoona|Bethel Park|Bethlehem|Chester|Erie|Harrisburg|Lancaster|Levittown|Mount Lebanon|Norristown|Penn Hills|Philadelphia|Pittsburgh|Reading|Ross Township|Scranton|State College|Wilkes-Barre|York”,
“Rhode Island|Barrington|Bristol|Central Falls|Cranston|Newport|Pawtucket|Providence|East Providence|North Providence|Warwick|West Warwick|Westerly|Woonsocket|Valley Falls”,
“South Carolina|Anderson|Aiken|Charleston|North Charleston|Columbia|Florence|Greenville|Goose Creek|Hilton Head Island|Mount Pleasant|Myrtle Beach|Rock Hill|Spartanburg|Summerville|Sumter”,
“South Dakota|Aberdeen|Brookings|Huron|Mitchell|Pierre|Rapid City|Sioux Falls|Watertown|Yankton”,
“Tennessee|Bristol|Bartlett|Chattanooga|Clarksville|Cleveland|Collierville|Columbia|Franklin|Germantown|HendersonvilleJackson|Johnson City|Kingsport|Knoxville|MemphisMorristown|Murfreesboro|Nashville-Davidson|Oak Ridge|Smyrna”,
“Texas|Abilene|Amarillo|Arlington|Austin|Baytown|Beaumont|Bedford|Brownsville|Bryan-College Station|Carrollton|Corpus Christi|Dallas|Denton|Edinburg|El Paso|Flower Mound|Fort Worth|Galveston|Garland|Grand Prairie|Harlingen|Houston|Irving|Killeen|Laredo|Lewisville|Longview|Lubbock|McAllen|McKinney|Mesquite|Midland|Missouri City|North Richland Hills|Odessa|Port Arthur|Plano|Pasadena|Round Rock|Richardson|San Antonio|San Angelo|Sugar Land|Tyler|Temple|The Woodlands|Victoria|Waco|Wichita Falls”,
“Utah|Salt Lake City”,
“Vermont|Montpelier”,
“Virginia|Richmond”,
“Washington|Olympia”,
“West Virginia|Charleston”,
“Wisconsin|Madison”,
“Wyoming|Cheyenne” // No comma on final entry
];

function SBoxSetup(IDS,ArrInfo,SFlag) {
s = document.getElementById(IDS);
var scnt = s.options.length;
for (var i = scnt-1; i >= 0 ; i–) { s.options[i] = null; }
var tmp = [];
s.options[s.options.length] = new Option(‘Select:’,”,false,false);
for (var i=0; i<ArrInfo.length; i++ ) {
tmp = ArrInfo[i].split(‘|’); // if (tmp[1] == ”) { tmp[1] = tmp[0]; }
if (SFlag == ”) {
s.options[s.options.length] = new Option(tmp[0],tmp[0],false,false);
} else {
if (tmp[0] == SFlag) {
for (var j=1; j<tmp.length; j++) {
s.options[s.options.length] = new Option(tmp[j],tmp[j],false,false);
}
}
}
// following not used at this time
// s.options[s.options.length] = new Option(ArrInfo[i],ArrInfo[i],false,false); // Other needs
}
}

</script>

<select name=’adstate’ id=”States” onclick=”SBoxSetup(‘Capitals’,STATES,this.value)”>
<script type=”text/javascript”>SBoxSetup(‘States’,STATES,”)</script>
</select>

<select name=’city’ id=”Capitals”>
<script type=”text/javascript”>SBoxSetup(‘Capitals’,STATES,’x’)</script>
</select>[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mikedhane spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...