@@ -15,26 +15,27 @@ function showLoader(isShow){
1515}
1616
1717// --------------------- Hide and Show input element to force user for select Post method ----------
18- function hide ( ) {
19- document . getElementById ( "postMethodButton" ) . style . visibility = "hidden" ;
20- }
21- function show ( state ) {
22- if ( state === 1 ) {
23- document . getElementById ( "postMethodButton" ) . style . visibility = "visible" ;
24- document . getElementById ( "name" ) . style . visibility = "hidden" ;
25- document . getElementById ( "mobile" ) . style . visibility = "hidden" ;
26- document . getElementById ( "username" ) . style . visibility = "hidden" ;
27- document . getElementById ( "password" ) . style . visibility = "hidden" ;
28- document . getElementById ( "result" ) . style . visibility = "hidden" ;
18+ function showCreateNewAccount ( state ) {
19+ switch ( state ) {
20+ case 1 : //Hide postMethodButton
21+ document . getElementById ( "postMethodButton" ) . style . visibility = "hidden" ;
22+ break ;
23+ case 2 : //Show postMethodButton and Hide all elements of Create New Account
24+ document . getElementById ( "postMethodButton" ) . style . visibility = "visible" ;
25+ document . getElementById ( "name" ) . style . visibility = "hidden" ;
26+ document . getElementById ( "mobile" ) . style . visibility = "hidden" ;
27+ document . getElementById ( "username" ) . style . visibility = "hidden" ;
28+ document . getElementById ( "password" ) . style . visibility = "hidden" ;
29+ document . getElementById ( "result" ) . style . visibility = "hidden" ;
30+ break ;
31+ case 3 : //Hide postMethodButton and Show all elements of Create New Account
32+ document . getElementById ( "postMethodButton" ) . style . visibility = "hidden" ;
33+ document . getElementById ( "name" ) . style . visibility = "visible" ;
34+ document . getElementById ( "mobile" ) . style . visibility = "visible" ;
35+ document . getElementById ( "username" ) . style . visibility = "visible" ;
36+ document . getElementById ( "password" ) . style . visibility = "visible" ;
37+ document . getElementById ( "result" ) . style . visibility = "visible" ;
2938 }
30- if ( state === 2 ) {
31- document . getElementById ( "postMethodButton" ) . style . visibility = "hidden" ;
32- document . getElementById ( "name" ) . style . visibility = "visible" ;
33- document . getElementById ( "mobile" ) . style . visibility = "visible" ;
34- document . getElementById ( "username" ) . style . visibility = "visible" ;
35- document . getElementById ( "password" ) . style . visibility = "visible" ;
36- document . getElementById ( "result" ) . style . visibility = "visible" ;
37- }
3839}
3940
4041// ------------------------------------------- Select Post Method ---------------------------------
@@ -43,25 +44,26 @@ function selectPostMethod(name){
4344 postMethod = 1 ;
4445 document . getElementById ( "postMethod" ) . textContent = "((Axios))" ;
4546 document . getElementById ( "postMethodButton" ) . style . display = "none" ;
46- show ( 2 ) ;
47+ showCreateNewAccount ( 3 ) ;
4748 }
4849 if ( name === 'async' ) {
4950 postMethod = 2 ;
5051 document . getElementById ( "postMethod" ) . textContent = "((Axios with Async))" ;
5152 document . getElementById ( "postMethodButton" ) . style . display = "none" ;
52- show ( 2 ) ;
53+ showCreateNewAccount ( 3 ) ;
5354 }
5455 if ( name === 'fetch' ) {
5556 postMethod = 3 ;
5657 document . getElementById ( "postMethod" ) . textContent = "((Fetch with Async))" ;
5758 document . getElementById ( "postMethodButton" ) . style . display = "none" ;
58- show ( 2 ) ;
59+ showCreateNewAccount ( 3 ) ;
5960 }
6061}
6162
6263// ----------------------------------------------- Login ------------------------------------------
6364function login ( ) {
6465 const result = document . getElementById ( "result" ) ;
66+ result . textContent = "" ; //Clear previous content, if we click again on sign in button
6567 const username = document . getElementById ( "username" ) ;
6668 const password = document . getElementById ( "password" ) ;
6769 showLoader ( true ) ;
@@ -306,7 +308,7 @@ function signup(){
306308 password . addEventListener ( "keyup" , function ( e ) { validate ( e ) } ) ;
307309
308310 // wait for select post method
309- show ( 1 ) ;
311+ showCreateNewAccount ( 2 ) ;
310312
311313 } else if ( isSignup ) {
312314 isSignup = false ;
0 commit comments