1-
1+ let usps ;
2+ let statesSelect = document . querySelector ( "#statesSelect" ) ;
23async function setUpForm ( ) {
34 try {
45 let statesResponse = await fetch ( "https://csumb.space/api/allStatesAPI.php" ) ;
@@ -9,7 +10,7 @@ async function setUpForm(){
910 let statesData = await statesResponse . json ( ) ;
1011 console . log ( statesData ) ;
1112
12- let statesSelect = document . querySelector ( "#statesSelect" ) ;
13+
1314
1415 for ( let stateData of statesData ) {
1516 let stateOption = document . createElement ( "option" ) ;
@@ -19,6 +20,7 @@ async function setUpForm(){
1920
2021 statesSelect . appendChild ( stateOption ) ;
2122 }
23+ console . log ( usps ) ;
2224
2325 } catch ( apiError ) {
2426 console . error ( apiError ) ;
@@ -39,7 +41,17 @@ async function zipCode(){
3941 let cityText = document . querySelector ( "#city" ) ;
4042 let latitudeText = document . querySelector ( "#latitude" ) ;
4143 let longitudeText = document . querySelector ( "#longitude" ) ;
42-
44+ let zipNotFound = document . querySelector ( "#zipError" ) ;
45+ if ( ! zipcodeData || ! zipcodeData . city ) {
46+ console . log ( "ZIP not found" ) ;
47+ zipNotFound . textContent = "Zip Code Not Found" ;
48+ zipNotFound . style . color = "red" ;
49+ cityText . textContent = "" ;
50+ latitudeText . textContent = "" ;
51+ longitudeText . textContent = "" ;
52+ return ;
53+ }
54+ zipNotFound . textContent = "" ;
4355 cityText . textContent = zipcodeData . city ;
4456 latitudeText . textContent = zipcodeData . latitude ;
4557 longitudeText . textContent = zipcodeData . longitude ;
@@ -56,7 +68,7 @@ document.querySelector("#passInput").addEventListener("focus", passwordSuggestio
5668async function passwordSuggestion ( ) {
5769 try {
5870 let passSugResponse = await fetch ( "https://csumb.space/api/suggestedPassword.php?length=8" ) ;
59- let passSugData = await passSugResponse . json ( ) ;
71+ let passSugData = await passSugResponse . json ( ) ;
6072
6173 let sugPass = document . querySelector ( "#suggestPassword" ) ;
6274
@@ -68,24 +80,75 @@ async function passwordSuggestion(){
6880}
6981
7082document . querySelector ( "#usernameInput" ) . addEventListener ( "change" , usernameChecker ) ;
83+ let userCheck ;
7184
7285async function usernameChecker ( ) {
7386 try {
74- let userCheck = document . querySelector ( "#usernameInput" ) . value ;
87+ userCheck = document . querySelector ( "#usernameInput" ) . value ;
7588 console . log ( userCheck )
7689 let userResponse = await fetch ( "https://csumb.space/api/usernamesAPI.php?username=" + userCheck ) ;
7790 let userData = await userResponse . json ( ) ;
7891 console . log ( userData )
7992
8093 if ( userData . available ) {
8194 document . querySelector ( "#userText" ) . textContent = "available" ;
95+ document . querySelector ( "#userText" ) . style . color = "green" ;
8296 }
8397 else {
8498 document . querySelector ( "#userText" ) . textContent = "not available" ;
99+ document . querySelector ( "#userText" ) . style . color = "red" ;
100+
85101 }
86102
87103
88104 } catch ( error ) {
89105 console . error ( error ) ;
90106 }
107+ }
108+ statesSelect . addEventListener ( "change" , counties ) ;
109+
110+ async function counties ( ) {
111+ try {
112+ let countySelect = document . querySelector ( "#countySelect" ) ;
113+ countySelect . innerHTML = "" ;
114+ let response = await fetch ( "https://csumb.space/api/countyListAPI.php?state=" + statesSelect . value ) ;
115+ let data = await response . json ( ) ;
116+ console . log ( data ) ;
117+ for ( let countyData of data ) {
118+ let countyOption = document . createElement ( "option" ) ;
119+ countyOption . value = countyData . county ;
120+ countyOption . textContent = countyData . county ;
121+ countySelect . appendChild ( countyOption ) ;
122+ }
123+ }
124+ catch ( error ) {
125+ console . log ( error ) ;
126+ }
127+ }
128+
129+ let submit = document . querySelector ( "#submit" ) ;
130+
131+ submit . addEventListener ( "click" , onSubmit ) ;
132+
133+ function onSubmit ( ) {
134+ if ( userCheck . length < 3 ) {
135+ document . querySelector ( "#userText" ) . textContent = "Must be Over 3 Characters!" ;
136+ document . querySelector ( "#userText" ) . style . color = "red" ;
137+ }
138+
139+ let passInput = document . querySelector ( "#passInput" ) . value ;
140+ let rePassInput = document . querySelector ( "#rePassInput" ) . value ;
141+
142+ if ( passInput . length < 6 ) {
143+ document . querySelector ( "#noMatch" ) . textContent = "Must be at Least 6 Characters!" ;
144+ document . querySelector ( "#noMatch" ) . style . color = "red" ;
145+ }
146+ else if ( passInput !== rePassInput ) {
147+ document . querySelector ( "#noMatch" ) . textContent = "Passwords Do Not Match!" ;
148+ document . querySelector ( "#noMatch" ) . style . color = "red" ;
149+
150+ }
151+ else {
152+ document . querySelector ( "#noMatch" ) . textContent = "" ;
153+ }
91154}
0 commit comments