JSFiddle - React, Tailwind, and code Playground

by Aaron Wallentine

HTML

<form name="enter_keyword" onSubmit="javascript:redirect(); return false;">
<table border="1" cellpadding="2" cellspacing="2" bgcolor="#7B97E0">
<tr>
<td>
<font color="#ffffff"><b>Enter keyword:</b></font>
</td>
<td><input type=text name=keyword>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value="Go!">
</td>
</tr>
</table>
</form>

JavaScript

function redirect() {
  // var done=0;
  var keyword = document.enter_keyword.keyword.value;
  //keyword=keyword.toLowerCase();
  //alert(keyword);

  var keyword_map = {
  	'toms': 'toms.com',
    'apple': 'apple.com',
    'orange': 'orange.com'
  };
  
  var protocol = document.location.protocol; // to handle https://, etc., like here on jsfiddle
  
  if (keyword in keyword_map) {
  	var target_url = protocol + '//' + keyword_map[keyword];
  	alert("Attempting to redirect you to: " + target_url);
  	window.location = target_url;
 
  } else {
  	alert("WARNING:Incorrect keyword you plonker!!!");
  }
  
  /*
  if (keyword=="toms") { window.location = protocol + "www.toms.com"; done=1; }
  if (keyword=="apple") { window.location = protocol + "www.apple.com"; done=1; }
  if (keyword=="orange") { window.location= protocol + "www.orange.com"; done=1; }
	if (done==0) { alert("WARNING:Incorrect keyword you plonker!!!"); }
  */
  

}