<?php

include "classes/html.class.php";

$html = new html("variety");
?>

    <div class='form'>
        <h2 style="font-size:2vw">ADD VARIETY:</h2>
        <hr><br>
        <input type='text' placeholder="NAME" id='name' class='form_input' /><br><br>
        
        <input type='submit' value='ADD' class='form_btn' onclick='ajax_func()' />

    </div>

    <script>
        function ajax_func() {
            // alert("Test");
            var name = document.getElementById('name').value;
          
            // Create an XMLHttpRequest object
            const xhttp = new XMLHttpRequest();
            // Define a callback function
            xhttp.onload = function() {
                // Here you can use the Data
                if (this.responseText != 1) {

                    alert(this.responseText);

                } else {
                    alert("VARIETY ADDED")
                    window.location.href = "add_home.php";
                }
            }

            xhttp.open("GET", "ajax/add_variety.ajax.php?name=" + name );
            xhttp.send();

        }
    </script>


</body>

</html>