2013-06-12 52 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>