I need to put together a form script to redirect the user based on what is entered into the form. I understand this can be done from JavaScript, I managed to put something together but it didn't do quite what I wanted it to do which is
User enters text, for example mysubdomain, then hits submit.
I would then like them to be forwarded to mysubdomain.mydomain.com. I managed to do the opposite so it directed to mydomain.com/mysubdomain.
Do you mean
<form onsubmit="window.location='http://'+this.subdomain.value+'.mydomain.com/';
return false">
<input type="text" name="subdomain" value="" />
</form>
using same domain as you are on ( details about the location object here at MDN ): and assuming the form is on xxxx.mydomain.com
<form
onsubmit="window.location='http://'+
this.subdomain.value+
location.hostname.substring(location.hostname.indexOf('.'))';
return false">
<input type="text" name="subdomain" value="" />
</form>
I think you could have a function that reloads the entered subdomain by the user + your domain so like window.location.assign(subdomain + ".yourdomain.com")
Take a look at the Location object as well.
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.