Replace text in the input form and visit

I want to create a form for my blog visitors like this:

<form name="myform" id="test">
<input type="text" name="url"/>
<input type="submit" value="submit"/>
</form>

If someone enters a URL: https://demo.website.com/page/blablabla.html

It will generate a URL: https://newwebsite.com/page/blablabla.html

So the point is: just change demo.website be newwebsite Is this possible with javascript or jQuery?

Answers 1

  • Working code would be somewhat like this

    <form name="myform" id="test">
    <input type="text" name="url" onblur="func(this)" />
    <input type="submit" value="submit"/>
    </form>
    
    <script>
        function func(elem){
            var _url = elem.value;
            var finUrl = _url.replace('demo.website','newwebsite');
            console.log(finUrl);
        }
    </script>
    

Related Articles