How to pass a variable in script tag of cshtml file to another javascript file?

Viewed 66

I have to send a input tag value in cshtml file to another js file in my project. I take the input from view and then saved that value in a javascript variable through getelementbyid, you can see the code here of script tag in cshtml file:

<script>
        function getInputValue(){
            var inputVal = document.getElementById("input").value;
            console.log(inputVal);
        }
        $(function () {
            $("#btnsubmit").click(function () {  
                var data = $("#myform").serialize();
                $.ajax({
                    url: '/api/studentlogin', 
                    type: "post",
                    contentType: 'application/x-www-form-urlencoded',
                    data: data,
                    success: function (result) {
                        @* window.open(`/home/mainpage`, "_self"); *@
                        @* console.log("REACHED!!!"); *@
                    }
                });
            });
    })
    </script>

Now I need to pass the inputVal variable in another js file, How can I do that? Thanks in Advance

0 Answers
Related