如何使用Javascript解析和形成字符串以打开网页

如何使用Javascript解析和形成字符串以打开网页,javascript,string,parsing,forms,Javascript,String,Parsing,Forms,我有一个表单,我需要运行一些javascript来解析表单中存储的页面信息以打开它 <script type="text/javascript"> function validateForm() { var x=document.forms["myForm"]["fname"].value if (x==null || x=="") { alert("First name must be filled out"); return false; } } functio

我有一个表单,我需要运行一些javascript来解析表单中存储的页面信息以打开它

<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["fname"].value
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}

function open()
{
     if (validateForm()) {
         1. get the value 
         2. parse the value to get year/month/date (?)
         3. compose the string of webpage (?)
         4. open the webpage (?)
     }
}
</script>

<form name="myForm" onsubmit="return open()" method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>

假设输入的格式始终为yyyy/mm/dd,则可以按如下方式解析字符串:

var strYear = fname.value.substring(0,4);
var strMonth = fname.value.substring(5,7);
var strDay = fname.value.substring(8,10);

var strURL = "http://abc/def"+strYear+"/"+strMonth+"/"+strYear+"_"+strMonth+"_"+strDay+".html";

// To change the same page with new URL, use:
  document.location.replace(strURL);
// To open a new popup window, use:
 window.open(strURL,"myWindow");
var strYear = fname.value.substring(0,4);
var strMonth = fname.value.substring(5,7);
var strDay = fname.value.substring(8,10);

var strURL = "http://abc/def"+strYear+"/"+strMonth+"/"+strYear+"_"+strMonth+"_"+strDay+".html";

// To change the same page with new URL, use:
  document.location.replace(strURL);
// To open a new popup window, use:
 window.open(strURL,"myWindow");