简体   繁体   中英

Form input and select values creates an URL

I have the following code which works great:

<script>
function process()
{
var url=document.getElementById("domain").value + document.getElementById("tld").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
URL: <input type="text" name="domain" id="domain"> <input type="text" name="tld" id="tld"> <input type="submit" value="go">
</form>

It gives me www.domain.com/google.com ('google' being domain and '.com' being tld)

BUT, I want to substitute the 'tld' input for select menu. I've tried this:

<script>
function process()
{
var url=document.getElementById("domain").value + document.getElementById("tld").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
URL: <input type="text" name="domain" id="domain"> <select name="tld"><option value=".com">.com</option></select><input type="submit" value="go">
</form>

I get http://www.domain.com/?domain=index&tld=.com

您尚未为选择标签指定ID。

select name="tld" id="tld">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM