表单值创建一个URL [英] Form value creates a url

查看:158
本文介绍了表单值创建一个URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一点额外代码创建一个非常简单的表单,以获得如下所述的结果:问题是我不知道如何去做。



我想要达到的效果:

我有一个表单,其中有一个文本输入框'URL'。我希望用户能够在框中输入一个数字。当用户提交表单时,他们应该被重定向到一个新的网站。新网站的网址将基于输入到表单中的编号。

网址的第一部分始终为: http:// name .com /



然后用户输入的数字将被附加到最后。因此,如果123456被输入到表格中,那么在提交表格时,用户将被采用为 http://name.com/123456



有没有人有任何关于我如何得到这项工作的想法?猜测它需要JavaScript或其他东西?

解决方案

 < script> 
函数process()
{
var url =http://name.com/+ document.getElementById(url).value;
location.href = url;
返回false;
}
< / script>
< form onSubmit =return process();>
网址:< input type =textname =urlid =url> < input type =submitvalue =go>
< / form>


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?

解决方案

<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>

这篇关于表单值创建一个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆