<?php
include "classes/html.class.php";
$html = new html("service types");
$db = new db();

?>
<div class='form'>
    <h2 style="font-size:2vw">ADD ASSET:</h2>
    <hr><br>
    <input type='text' placeholder="SERVICE TYPE NAME" id='name' name='name' class='form_input' /><br><br>
    <label style="font-size:1.5vw">ODO TYPE: </label><br>
    <select id='odo_type' class='form_input'>
        <option></option>
        <option>KM</option>
        <option>Hours</option>
        <option>Days</option>
    </select><br><br>
    <input type='text' placeholder="SERVICE INTERVAL" id='interval' class='form_input' /><br><br>
   

    <input type='submit' value='ADD' class='form_btn' onclick='ajax_func()' />

</div>

<script>
    

    function ajax_func() {
        // alert("Test");
        name = document.getElementById('name').value;
        odo_type = document.getElementById('odo_type').value;
        interval = document.getElementById('interval').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 {
                window.location.href = "service_types.php";
            }
        }

        xhttp.open("GET", "ajax/add_service_type.ajax.php?name=" + name + "&odo_type=" + odo_type + "&interval=" + interval);
        xhttp.send();

    }
</script>


</body>

</html>