Why you want to convert this code to JavaScript?
I guess you are doing Asp.Net development. If my assumption is correct then use "
Ajax". Using this you can execute your Server side code(VB/C#) from JavaScript.
Have a look at my below Tips/Tricks Article on "
Asp.Net Ajax". In this article, I have used C# but I think it should not be hurdle to understand concept of "
Ajax".
Simplifying Asp.Net Core Ajax
Hope this is helpful.