Form value creates a URL

前端 未结 3 1459
灰色年华
灰色年华 2020-12-14 05:41

I am trying to create a very simple form with a little bit of extra code to get the results as described below: the problem is I don\'t know how to go about doing it.

<
相关标签:
3条回答
  • 2020-12-14 06:01
    <script>
        function process()
        {
            var url = "http://name.com/" + document.getElementById("url").value;
            location.href = url;
            return false;
        }
    </script>
    
    <form onSubmit="return process();">
        URL: <input type="text" name="url" id="url">
        <input type="submit" value="go">
    </form>
    
    0 讨论(0)
  • 2020-12-14 06:02

    You can add onsubmit="this.action='http://google.com/'+this.fieldName.value;" to your tag.

    0 讨论(0)
  • 2020-12-14 06:22

    This should do it:

    <script type="text/javascript">
        function goToPage() {
            var page = document.getElementById('page').value;
            window.location = "http://name.com/" + page;
        }
    </script>
    <input type="text" id="page" />
    <input type="submit" value="submit" onclick="goToPage();" />
    
    0 讨论(0)
提交回复
热议问题