2016-02-29 64 views
0

我想在完成後隱藏第一個表單,然後在第一個表單的同一位置顯示第二個表單,之後我會將輸入的信息發送到電子郵件。我試圖只顯示一個窗體完成後,然後形式2,窗體2不會顯示?

社區可以提出我需要改變我的代碼,謝謝。

function showhide() { 
 
    var myDiv = document.getElementById("form2"); 
 
    var div = document.getElementById("form1"); 
 
    if (div.style.display !== "none") { 
 
    div.style.display = "none"; 
 
    } else { 
 
    div.style.display = "form2"; 
 
    } 
 
};
#form2 { 
 
    display: none; 
 
}
<div class="col-md-4" id="form1"> 
 
    <div class="panel panel-default"> 
 
    <div class="panel-heading"> 
 
     <h3>Help is here!</h3> 
 
    </div> 
 
    <div class="panel-body"> 
 
     <!-- HTML Form (wrapped in a .bootstrap-iso div) --> 
 
     <div class="bootstrap-iso"> 
 
     <div class="container-fluid"> 
 
      <div class="row"> 
 
      <div class="col-md-12 col-sm-3 col-xs-12"> 
 
       <form method="post"> 
 
       <div class="form-group "> 
 
        <label class="control-label " for="name"> 
 
        First name 
 
        </label> 
 
        <input class="form-control" id="name" name="name" type="text" required/> 
 
       </div> 
 
       <div class="form-group "> 
 
        <label class="control-label " for="name1"> 
 
        Last name 
 
        </label> 
 
        <input class="form-control" id="name1" name="name1" type="text" required/> 
 
       </div> 
 
       <div class="form-group "> 
 
        <label class="control-label " for="tel"> 
 
        Telephone # 
 
        </label> 
 
        <input class="form-control" id="tel" name="tel" type="text" required/> 
 
       </div> 
 
       <div class="form-group "> 
 
        <label class="control-label requiredField" for="email"> 
 
        Email 
 
        <span class="asteriskField"> 
 
     * 
 
    </span> 
 
        </label> 
 
        <input class="form-control" id="email" name="email" type="text" required/> 
 
       </div> 
 
       <div> 
 
        <button id="button" onclick="showhide()">Click Me</button> 
 
       </div> 
 
      </div> 
 
      </form> 
 
      </div> 
 
     </div> 
 
     </div> 
 
    </div> 
 

 
    <div class="col-md-12 " id="form2"> 
 
     <div class="panel panel-default"> 
 
     <div class="panel-heading"> 
 
      <h3>One more step</h3> 
 
     </div> 
 
     <div class="panel-body"> 
 
      <!-- HTML Form (wrapped in a .bootstrap-iso div) --> 
 
      <div class="bootstrap-iso"> 
 
      <div class="container-fluid"> 
 
       <div class="row"> 
 
       <div class="col-md-12 col-sm-3 col-xs-12"> 
 
        <form method="post"> 
 
        <div class="form-group "> 
 
         <label class="control-label " for="state"> 
 
         What state are you in? 
 
         </label> 
 
         <select class="form-control"> 
 
         <option>Alabama</option> 
 
         <option>Alaska</option> 
 
         <option>Arizona</option> 
 
         <option>Arkansas</option> 
 
         <option>California</option> 
 
         <option>Colorado</option> 
 
         <option>Connecticut</option> 
 
         <option>Delaware</option> 
 
         <option>Florida</option> 
 
         <option>Georgia</option> 
 
         <option>Hawaii</option> 
 
         <option>Idaho</option> 
 
         <option>Illinois Indiana</option> 
 
         <option>Iowa</option> 
 
         <option>Kansas</option> 
 
         <option>Kentucky</option> 
 
         <option>Louisiana</option> 
 
         <option>Maine</option> 
 
         <option>Maryland</option> 
 
         <option>Massachusetts</option> 
 
         <option>Michigan</option> 
 
         <option>Minnesota</option> 
 
         <option>Mississippi</option> 
 
         <option>Missouri</option> 
 
         <option>Montana Nebraska</option> 
 
         <option>Nevada</option> 
 
         <option>New Hampshire</option> 
 
         <option>New Jersey</option> 
 
         <option>New Mexico</option> 
 
         <option>New York</option> 
 
         <option>North Carolina</option> 
 
         <option>North Dakota</option> 
 
         <option>Ohio</option> 
 
         <option>Oklahoma</option> 
 
         <option>Oregon</option> 
 
         <option>Pennsylvania Rhode Island</option> 
 
         <option>South Carolina</option> 
 
         <option>South Dakota</option> 
 
         <option>Tennessee</option> 
 
         <option>Texas</option> 
 
         <option>Utah</option> 
 
         <option>Vermont</option> 
 
         <option>Virginia</option> 
 
         <option>Washington</option> 
 
         <option>West Virginia</option> 
 
         <option>Wisconsin</option> 
 
         <option>Wyoming</option> 
 
         </select> 
 
        </div> 
 
        <div class="form-group "> 
 
         <label class="control-label " for="owe"> 
 
         How much do you owe on your house? 
 
         </label> 
 
         <select class="form-control"> 
 
         <option>Select one</option> 
 
         <option>owe less than $75,000 on home</option> 
 
         <option>owe between $75,000 to 100,000</option> 
 
         <option>owe between $100,000 to $200,000</option> 
 
         <option>owe between $300,000 to $400,000</option> 
 
         <option>owe between $400,000 to $500,000</option> 
 
         <option>owe more than $500,000 on home</option> 
 
         </select> 
 
        </div> 
 
        <div class="form-group "> 
 
         <label class="control-label " for="lender"> 
 
         Who is your lender? 
 
         </label> 
 
         <input class="form-control" id="lender" name="lender" type="text" /> 
 
        </div> 
 
        <div class="form-group "> 
 
         <label class="control-label requiredField" for="foreclose-date"> 
 
         Is there a foreclosure sales auction date set? 
 
         <label class="radio-inline"> 
 
          <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">Yes 
 
         </label> 
 
         <label class="radio-inline"> 
 
          <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">No 
 
         </label> 
 
         </label> 
 
        </div> 
 
        <div class="form-group "> 
 
         <label class="control-label " for="property"> 
 
         Property address 
 
         </label> 
 
         <input class="form-control" id="property" name="property" type="text" /> 
 
        </div> 
 
        <div class="form-group"> 
 
        </div> 
 
        <div> 
 
         <button class="btn btn-primary " name="submit" type="submit"> 
 
         Submit 
 
         </button> 
 
        </div> 
 
       </div> 
 
       </form> 
 
       </div> 
 
      </div> 
 
      </div> 
 
     </div> 
 
     </div>

+0

好一件事「窗口2」是不是'div.style.display'有效的設置 - 你爲什麼不重命名變量' form1'和'form2'而不是'myDiv'和'div',那麼你可以'form1.style.display ='none''和'form2.style.display ='block''等。 –

+0

@ Two-BitAlchemist - 即使它無效,它仍應顯示它。 – Derek

+1

@OliverQueen但是他也在混合var名稱 - 'div'是form1,你看。在CSS中設置form2'display:none',然後從不對'myDiv'做任何事情,所以它保持這種狀態。 –

回答

1

如果你想發送在一個步驟中,你必須只使用一個<form>

因此,在輸入欄外「完全」使用<form> DS。

,你想交換,你可以用一個簡單的javascript禁用像

function showhide() { 
    document.getElementById("form2").style.display = "block"; 
    document.getElementById("form1").style.display = "none"; 
}; 

隊的第一個按鈕type="button"防止提交的組件。

這裏完整版本:https://jsfiddle.net/6e2otxvq/1/更新:整潔的HTML

0

更改您的功能顯示隱藏(),如下圖所示

function showhide(){ 
    var myDiv = document.getElementById("form2"); 
    var div = document.getElementById("form1"); 

    //to hide form-1 
    div.style.display = "none"; 

    //to display form-2 
    myDiv.style.display = "block"; 
} 
+0

這只是讓它消失,接下來不會出現,但感謝@Nirav –