2013-06-12 235 views
0

我正在創建一個動態表與我的BD上的查詢,問題是我想要禁用每次我提交表上的按鈕, 我想獲得沒有頁面加載提交的表單,以便禁用按鈕是可見的。禁用單擊表格或提交按鈕時提交表單

<?php 
      $theCounter=0; 
      while($row = mysql_fetch_object($result)) 
      { 

     ?> 

      <form id="id" action="table.php" method="post"> 
      <input type="hidden" value="<?php echo $row->id_table; ?>" name="idUser"> 
       <tr> 
        <td><?php echo $row->id_userS; ?></td> 
        <td><?php echo $row->username_s; ?></td> 
        <td><?php echo $row->num_people;  ?></td> 
        <td><?php echo $row->start_time; ?></td> 
        <td> 
         <input type="submit" name="delete_check" value="Eliminar"> 
        </td> 
        <td> 
         <input type="submit" name="push_check" value="Enviar Push"> 
        </td> 
       </form> 
     <?php 
      $theCounter++; 
      } 

     ?> 

該按鈕我想禁用或隱藏其名爲「push_check」的按鈕。 不要緊,如果我禁用按鈕或隱藏按鈕

在此先感謝!

+0

如何分配一個id到該按鈕並通過JavaScript禁用相同的? –

+0

是的,我已經嘗試過,但問題是每次按按鈕,頁面刷新和它被重新創建! PD:對不起,我的英文 – user2465233

+0

你不能通過提交這樣的表單來實現你所嘗試的。如果您不想重新加載頁面,則必須通過ajax提交表單。 – NullPointerException

回答

0

嗨,我管理這個做到這一點:

<?php 
         $push_button = $row->time_push; 
         if($push_button==0) 
         { 
         ?> 
        <td> 
         <input type="submit" id='push$thecounter' name="push_check" value="Enviar Push"> 
        </td> 
        <?php 
         } 
         ?> 

既然我已經做查詢到我的數據庫,並且按鈕正在進行更改,即時檢查是否改變了它已經制作的,所以如果沒有,即時通訊顯示按鈕!非常感謝您的所有評論!

0

PHP: -

<?php 
     $theCounter=0; 
     while($row = mysql_fetch_object($result)) 
     { 

Echo " 

     <form id='id' action='table.php' method='post'> 
     <input type='hidden' value='$row->id_table;' name='idUser'> 
      <tr> 
       <td>$row->id_userS</td> 
       <td>$row->username_s</td> 
       <td>$row->num_people</td> 
       <td>$row->start_time</td> 
       <td> 
        <input type='submit' id='del$thecounter' name='delete_check' value='Eliminar' onclick='hide(del$thecounter)'> 
       </td> 
       <td> 
        <input type='submit' id='push$thecounter' name='push_check' value='Enviar Push' onclick='hide(push$thecounter)'> 
       </td> 
      </form> 
"; 
     $theCounter++; 
     } 
?> 

現在使用JavaScript: -

function hide(a) 
{ 
    document.getElementById(a).style.visibility="hidden"; 
} 
+0

以上是否需要你的工作?很快回復 – user2360906

+0

需求是(或者我所知道的)按鈕應該被禁用/隱藏在後面的頁面上,一旦點擊就重新加載。 –

+0

是的,正如Darshan所說,我會嘗試使用$ theCounter – user2465233

0

如果您希望按鈕上的所有頁面加載被禁用後的第一次提交,那麼你需要存儲一些標誌在會話中將指示該按鈕已被點擊。而且你需要檢查每個頁面加載的標誌。

0

我不知道如果我理解你想才達到的一切,但這裏是我做出來你的問題:

<script> 

    document.forms[0].onsubmit = function(e){ 

     e.preventDefault(); // at the beginning stop page from being reloaded by the script 
     var form = e.currentTarget; // get form 
     form.push_check.disabled = true; // set submit-button disabled 

     if(form.idUser.value){ // send data if there is data to send 
      document.forms[0].onsubmit = null; // set event listener null otherwise onsubmit is a forever-loop 
      document.forms[0].submit(); // send finally data to the php-script 
     } 
     else{ 
      form.mysubmit.disabled = false; // there was no data to send 
     } 
    } 
</script> 

可以後或身體標籤內把這個小腳本。它應該在每個瀏覽器中工作。

0

還有一個方法,以防止加載頁面使用目標

<form action='' method='POST' target='upload_target' onsubmit='hide(dynamicid)'> 

fields between form..... 
<input type='submit' id='dynamicid'/> 
<iframe id='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe> 
</form>