Form value creates a url

2019-01-22 04:51发布

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

What i am trying to achieve:

I have a form which has one text input box with the name 'url'. I want the user to be able to input a number into the box. When the user submits the form they should be redirected to a new website. The new websites URL will be based on the number inputted into the form.

The first part of the url will always be: http://name.com/

Then the number that the user inputted will be attached to the end. So if 123456 is entered into the form then on submission of the form the user would be taken to http://name.com/123456

Does anyone have any ideas about how i can get this working? Guessing it will require JavaScript or something?

标签: html forms url
3条回答
贪生不怕死
2楼-- · 2019-01-22 05:20

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();" />
查看更多
The star\"
3楼-- · 2019-01-22 05:22
<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>
查看更多
三岁会撩人
4楼-- · 2019-01-22 05:38

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

查看更多
登录 后发表回答