Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

html - Form value creates a URL

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.

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 website's 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

How can I get this working? I am guessing it will require JavaScript or something.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...