-1

I am working on a project where I need to send my data to the firebase of the form.

Link - http://ietvit.com/hackoff/

Github repo link - https://github.com/vivanks/hackoffproject

But on filling out the form it should pop up alert window and submit the form but when I open the website for the first time it does not do anything when it refreshes instead it starts to work perfectly but not for the first time. Any reason why or any suggestions to prevent.

Example :

I open my website for the first time and fills out the subscribe form but it just simply refreshes the page instead of updating firebase and pop-ing alert window.

My html form -

<form class="contact100-form validate-form">
                        <div class="wrap-input100 m-b-10 validate-input" data-validate = "Name is required">
                            <input id="name" class="s2-txt1 placeholder0 input100" type="text" name="name" placeholder="Your Name">
                            <span class="focus-input100"></span>
                        </div>
    
                        <div class="wrap-input100 m-b-20 validate-input" data-validate = "Email is required: ex@abc.xyz">
                            <input id="email" class="s2-txt1 placeholder0 input100" type="text" name="email" placeholder="Email Address">
                            <span class="focus-input100"></span>
                        </div>
    
                        <div class="w-full">
                            <p class="s2-txt3 p-t-18">
                        And don’t worry, we hate spam too! You can unsubcribe at anytime.
                    </p><br>
                            <button id="submitBtn" onclick="submitDetail()" name="submit" class="flex-c-m s2-txt2 size4 bg1 bor1 hov1 trans-04">
                                Submit
                                </button>
                            
                        </div>
                    </form>

My java script -

var nameText = document.getElementById("name");
var emailText = document.getElementById("email");
var submitBtn = document.getElementById("submitBtn");

const firebaseRef = firebase.database().ref();




function submitDetail(){

    var nText = nameText.value;
    var eText = emailText.value;
        
    firebaseRef.push().set({
        name : nText,
        email : eText
    });

    window.alert("Subscribed Successfully")

}
Community
  • 1
  • 1
Vivank Sharma
  • 395
  • 1
  • 4
  • 11

1 Answers1

0

                    <div class="wrap-input100 m-b-20 validate-input" data-validate = "Email is required: ex@abc.xyz">
                        <input id="email" class="s2-txt1 placeholder0 input100" type="text" name="email" placeholder="Email Address">
                        <span class="focus-input100"></span>
                    </div>

                    <div class="w-full">
                        <p class="s2-txt3 p-t-18">
                    And don’t worry, we hate spam too! You can unsubcribe at anytime.
                </p><br>
                        <button id="submitBtn" onclick="submitDetail(event)" type="submit" name="submit" class="flex-c-m s2-txt2 size4 bg1 bor1 hov1 trans-04">
                            Submit
                            </button>

                    </div>
                </form>

And in js to prevent reload :

function submitDetail(ev){
ev.preventDefault();
var nText = nameText.value;
var eText = emailText.value;

firebaseRef.push().set({
    name : nText,
    email : eText
});

window.alert("Subscribed Successfully")

}

Madhan Varadhodiyil
  • 2,086
  • 1
  • 14
  • 20