2012-03-09 93 views
0

我的用戶可以輸入多個地址,但我想要一個實際的按鈕來生成額外的字段,因爲只有一個地址是強制性的,空字段看起來很醜!我也需要額外的地址進入mysql數據庫。 我會怎麼做的JavaScript如果PHP是不可能 一些代碼,可以幫助:添加動態字段形成

<td width="732" valign="top"><p> 
<h3 class="main">Address Details</h3> 
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory. 
However it would be helpful if you could insert 3 addresses: 
<ul> 
<li>Permanent home address</li> 
<li>Postal address (where you will be from June to September)</li> 
<li>Local address (where you currently live)</li> 
</ul>  
<?php 
if(!empty($err)) { 
    echo "<div class=\"msg\">"; 
    foreach ($err as $e) { 
    echo "* $e <br>"; 
    } 
    echo "</div>";  
    } 
?> 
<br> 
<form action="address.php" method="post" name="regForm" id="regForm" > 
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms"> 
<tr> 
<td>Street<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Street" type="text" id="Street" class="required" size="50"> 
</tr> 
<tr> 
<td>Line 2 
</td> 
<td><input name="Line2" type="text" id="Line2" class="required" size="50"> 
</tr> 
<tr> 
<td>Line 3 
</td> 
<td><input name="Line3" type="text" id="Line3" class="required" size="50"> 
</tr> 
<tr> 
<td>Town<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Town" type="text" id="Town" class="required" size="30"> 
</tr> 
<tr> 
<td>Postcode<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10"> 
</tr> 
<tr> 
<td>Country <font color="#CC0000">*</font></span></td> 
<td><select name="Country" class="required" id="select8"> 
      <option value="" selected></option> 
      <option value="Afghanistan">Afghanistan</option> 
      <option value="Albania">Albania</option> 
      (etc) 
      </select></td> 
</tr> 
<tr> 
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Tele" type="text" id="Tele" class="required" > 
</tr> 
<tr> 
<td>Fax<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Fax" type="text" id="Fax" class="required" > 
</tr> 
<tr> 
<td>Mobile<span class="required"><font color="#CC0000">*</font></span> 
</td> 
<td><input name="Mobile" type="text" id="Mobile" class="required" > 
</tr> 
<tr> 
<td>Type <font color="#CC0000">*</font></span></td> 
<td><select name="Type" class="required" id="select8"> 
      <option value="" selected></option> 
      <option value="H">Home</option> 
      <option value="P">Postal</option> 
      <option value="L">Local</option> 


</table> 
<p align="center"> 
<input name="doAddress" type="submit" id="doAddress" value="Submit"> 
+1

這個問題與Java有什麼關係?當你的意思是'Javascript'時,你用'Java'錯誤標記了嗎? – 2012-03-09 17:36:12

+0

爲什麼標記'java'? – 2012-03-09 17:38:29

+0

hello ??? <點擊,點擊,點擊>是這件事嗎? – 2012-03-09 17:41:51

回答

0

好。首先,您需要刪除表格格式。這是一個非常過時和可怕的做法,用於創建表單(不靈活)。你可以在CSS中創建所有這些。

秒,css是你的答案。如果您希望該字段出現在單擊按鈕上,則添加一個JavaScript事件綁定以刪除其中display = none的css類或css屬性。使用像jQuery這樣的庫會使這非常簡單。

如果你想根據服務器的響應來顯示字段,那麼當點擊提交時,你需要發送一個ajax請求(再次jQuery將使這非常簡單),然後更新css類或顯示屬性上ajax請求的成功回調方法。