2014-06-25 44 views
-1

我正在用mysql和php製作一個基本的新客戶數據庫。我希望當用戶點擊另一個輸入字段的單選按鈕「不同的郵寄地址」來顯示郵寄地址時。林不太清楚如何處理這與輸入而不是變量。有沒有辦法做一個if語句這裏是我的HTML格式代碼如下html表單 - 需要幫助有新的輸入區域填充單選按鈕

<form method="POST" action="insert.php"> 
    <fieldset> 
    <legend>New Customer data</legend> 
    <label>Complete Below</label> 

<div class="controls controls-row"> 
    <input class="span4" name="firstname" type="text" placeholder="First name"> 
    <input class="span3" name="lastname" type="text" placeholder="Last Name"> 
    <input class="span3" name="phone" type="text" placeholder="Phone"> 

</div> 
<div class="controls controls-row"> 
    <input class="span4" name="address" type="text" placeholder="Address"> 
    <input class="span2" name="city" type="text" placeholder="City"> 
    <input class="span1" name="state" type="text" placeholder="State"> 
</div> 
<div class="controls controls-row"> 
    <input class="span4" name="zip" type="text" placeholder="Zip Code"> 
    <input class="span2" name="email" type="text" placeholder="Email"> 
    <input class="span2" name="ccemail" type="text" placeholder="cc email"> 
</div> 





    <span class="help-block">When is the customers due date monthly</span> 
     <label class="radio"> 
    <input type="radio" name="duedate" id="optionsRadios1" value="1" checked> 
1st of the month</label> 
<label class="radio"> 
    <input type="radio" name="duedate" id="optionsRadios2" value="15"> 
15th of the month 
</label>  
    <span class="help-block">Mailing address</span> 
<label class="radio"> 
    <input type="radio" name="mailingaddress" id="optionsRadios3" value="1" checked> 
Check if mailing address is the same as the service address 
</label> 
<label class="radio"> 
    <input type="radio" name="mailingaddress" id="optionsRadios4" value="0"> 
Check if mailing address is different 
</label> 

        <button type="submit" class="btn btn-primary">Submit</button> 



    </fieldset> 
</form> 
+2

您可能需要一些jacascript來隱藏字段或根據選擇顯示它們或根據選擇創建它們。從你的問題來看,我認爲你正在尋找一個php解決方案,它不會像php是服務器端一樣工作。這意味着如果沒有頁面刷新,您將無法監控交互。 – ScottMcGready

+0

您已將jquery標籤添加到您的問題中......也許jquery可以幫助您解決這個問題? –

+0

我認爲你需要閱讀關於JavaScript和jQuery的內容。 –

回答

0

使用jQuery,有兩個輸入,最初是隱藏的。一旦用戶選中了這兩個輸入框中的「$ .show()」, Id有一個包含兩個輸入的div,並根據是否選中該框來顯示或隱藏div

0

您可以試試這個。

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" > 
</script> 
<script> 
    $(document).ready(function(){ 
$("#checkme").on('change',function(){ 
    if($("#checkme").is(":checked")){ 
     $("input#myemail").fadeIn(); 
    }else{ 
     $("input#myemail").fadeOut(); 
    } 
}); 
    }); 
</script> 
</head> 
<body> 
show: <input type="checkbox" id="checkme" /><br /> 
<input type="text" id="myemail" hidden /> 
</body> 
</html>