2016-07-22 5 views
0

ボタンをクリックしたときに進捗バーを表示する必要があります。以下はコードですが、ボタンをクリックするとコンソールにメッセージが表示されますが、divの要素converting_progは表示されません。POST時にPHPがdiv要素を表示する

以下のコードにはどのような誤りがありますか?

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script> 
     <?php 
      //process the forms and upload the files 
      if ($_POST) { 
       //specify folder for file upload 
       $user = $_GET["user"]; 
       ?> 
       <script> 
        console.log("posting..."); 
       </script> 
       <script type="text/javascript">document.getElementById('converting_prog').style.display = 'block';</script> 
       <?php 
      } 
     ?> 
    </head> 
    <body> 
     <div id="outPopUp"> 
      <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
       <input class="btn" name="submit" type="submit" id="submit" value="Submit"/> 
      </form> 
      <div id="converting_prog" class="progress" style="display:none; margin-right:20px;margin-left:20px;margin-top:20px;width:auto"> 
       <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%"> 
        Converting % 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 
+2

あなたはconverting_prog要素の後にスクリプトをシフトすることができます。 –

+1

一般に、本体を閉じる前に、すべてのページの末尾に '

1

フォームが送信された後にポストボタンを検出しているので(珍しい)、ページが生成された時点でフォームが送信されているかどうかは既に分かります。そのためブロックを非表示にするためのJSコードは必要ありません。必要がない場合は単に印刷しないでください。

if (!$_POST) { 
?> 
    <div id= "converting_prog" class="progress" style="margin-right:20px;margin-left:20px;margin-top:20px;width:auto"> 
    <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%"> 
     Converting % 
    </div> 

</div> 
<?php 
} 

既存の進行状況バーコードの周りにあれば追加してください。

+1

私は、 'if($ _POST)'と 'display:none'を除いてdivを表示するだけでいいと思います。 – Scimonster

+0

これは、送信をクリックする前にのみ印刷されます。 – Scimonster

+0

$ _POST配列をチェックし、値の印刷に応じて余分なブロックがないかどうかを調べるのはもっと理想的でした。私はそれをテストする環境がなかった。しかし、もしあなたがそれを使用するつもりなら、余分な仕事をしてください。 $ _POSTを印刷し、ページが初めて開かれたときの内容とフォームが提出されたときの内容を確認します。 – MilanG

1

使用スクリプトタグの間、このコード:

document.getElementById("id of your button").addEventListener("click", function(){ 
document.getElementById("converting_prog").style.display = "block";}); 
1

は、私が正常に動作しているコードを次のようにステータスと位置を確認し、あなたの$ _POSTを変更:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script> 
    </head> 
    <body> 
     <div id="outPopUp"> 
     <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
      <input class="btn" name="submit" type="submit" id="submit" value="Submit" /> 
     </form> 
     <div id= "converting_prog" class="progress" style="display:none; margin-right:20px;margin-left:20px;margin-top:20px;width:auto"> 
      <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%"> 
       Converting % 
      </div> 
     </div> 
     </div> 
    </body> 
</html> 
<?php 
//process the forms and upload the files 
if (isset($_POST['submit'])) { 
    //specify folder for file upload 
    //$user = $_GET["user"]; 
    ?> 
    <script> 
    $('#converting_prog').show(); 
    </script> 
    <?php 
} ?> 
関連する問題