-1

I'm trying to make an HTML form with a Text box labeled "enter your store ID" and a submit button.

Then when the submit button is hit I want them re-directed to a different website with the subdomain being what entered.

Examples:
if "12345" is entered, they get redirected to 12345.myothersite.com
if "987654" is entered, they get redirected to 987654.myothersite.com

Sparky
  • 98,165
  • 25
  • 199
  • 285
Jim
  • 15
  • 2
  • Try this thread, http://stackoverflow.com/questions/1167068/apache-mod-rewrite-a-subdomain-to-a-subfolder-via-internal-redirect. – chris85 Mar 21 '16 at 21:04

2 Answers2

1

Since you've tagged this jQuery I presume you are okay with a jQuery answer.

HTML:

<form id="form">
  <input id="subdomain"/>
  <input type="submit"/>
</form>

JavaScript:

$(document).ready(function() {
  $("#form").submit(function(event) {
    event.preventDefault();
    window.location.href = "http://" + $("#subdomain").val() + ".somesite.com/"
  });
});
Chris
  • 5,571
  • 2
  • 20
  • 32
  • `window.location = ...` won't work in some browsers, `window.location.href = ...` is compatible with most browsers – Maposa Takalani Mar 21 '16 at 21:19
  • I've not seen it in any modern browser, but you are right that it could break some old browsers. I'll update my answer. – Chris Mar 21 '16 at 21:30
0
window.location.href = document.getElementById('inputBox').value + '.myothersite.com';

Example:

https://jsfiddle.net/53q2jf2k/

<form onsubmit="return false">
    <input type="text" id="inputBox"/>
    <button  onclick="changeURL()" >Submit</button>
</form>


function changeURL() {
    window.location.href = document.getElementById('inputBox').value + '.myothersite.com';

  alert(document.getElementById('inputBox').value + '.myothersite.com')
}
chris85
  • 23,846
  • 7
  • 34
  • 51
Sumama Waheed
  • 3,579
  • 3
  • 18
  • 32