title: How to parse and form the string to open the webpage out of it with Javascript
body: <p>I have a form and I need to run some javascript to parse the page info stored in the form to open it.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  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 (?)
       }
  }
  &lt;/script&gt;
  
  &lt;form name="myForm" onsubmit="return open()" method="post"&gt;
  First name: &lt;input type="text" name="fname"&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The input is of the format <code>2011/03/05</code> and I need to open <code>http://abc/def/2011/03/2011_03_05.html</code>. It requires parsing the date, and append string, and open the page. </p>
  
  <h2>ANSWER</h2>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function validateForm()
  {
  var x=document.forms["myForm"]["fname"].value;
  if (x==null || x=="")
    {
    alert("First name must be filled out");
    return false;
    }
    return true;
  }
  
  function openPage()
  {   
       if (validateForm()) {
          var value = document.forms["myForm"]["fname"].value
  
          var strYear = value.substring(0,4);
          var strMonth = value.substring(5,7);
          var strDay = value.substring(8,10);
  
          var strURL = "http://abc/def/"+strYear+"/"+strMonth+"/"+strYear+"_"+strMonth+"_"+strDay+".html";
          alert("strURL");
  
          //document.location.replace(strURL)
          //document.write(strURL);
          window.open(strURL,"myWindow");
       }
  }
  &lt;/script&gt;
  
  &lt;form name="myForm" onsubmit="openPage()" method="post"&gt;
  First name: &lt;input type="text" name="fname"&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>