2015-04-14 12 views
0

我正在生成一個報告,我需要輸入值的html格式。我將輸入給表單的表單(頁面的HTML)保存爲一個變量。但是,當我保存它的輸入不會進入它。如何保存帶有輸入值的page-html,提交到變量

如何將值保存到它?

HTML:

 <form method="POST" action="<?php echo BASE_URL . 'php/processing/formInput/formDataInputProcesing.php?id=' . $_GET['id']; ?>" > 
     <div id="formHtml"> 
     <?php echo $formHtml; ?>    
     <hr> 
     </div> 
     <input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" > 
     <div class="text-center"> 
      <button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button> 
     </div> 
     <hr> 
    </form> 

使用Javascript/JQuery的:

<script type="text/javascript"> 

     $('#submitData').click(function(){ 
      var html = $('#formHtml').html(); 
      $('#formHtmlValue').val(html); 
     }); 
    </script> 
+0

您的html必須在其輸入標記中添加新值的值屬性 – madalinivascu

+0

您確定'$ formHtml'有值嗎? – kosmos

+0

是的,我需要有新的值輸入保存在正確的位置和整個HTML格式的數據庫中,因此我需要最後一個提交變量 – Shaggie

回答

0

我使用老方法

<form method="POST" onsubmit="setValue(this)" action="<?php echo BASE_URL . 'php/processing/formInput/formDataInputProcesing.php?id=' . $_GET['id']; ?>" > 
    <div id="formHtml"> 
    <?php echo $formHtml; ?>    
    <hr> 
    </div> 
    <input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" > 
    <div class="text-center"> 
     <button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button> 
    </div> 
    <hr> 
</form> 


<script language=javascript> 
    function setValue(v) 
    { 
    var tableContent=document.getElementById("formHtml").innerHTML; 
v.formHtmlValue.value=tableContent; 
return true;  
} 
</script> 
+0

沒有。價值觀並沒有達到它。我需要捕捉用戶輸入的值而不是表單內容 – Shaggie

0

下面是另一個例子:

<html> 
    <script src="https://code.jquery.com/jquery-git2.min.js"></script> 
    <body> 
     <form method="POST" action="abc.php?id=123" onsubmit="setValue()" > 
      <div id="formHtml"> 
       <table> 
        <tr> 
         <td> 
         <input type=text name="t1"><span id="t1Value"></span> 
         <input type=radio name="r1" value="r1" checked><span id="r1Value"></span> 
         <input type=checkbox name="c1" value="c1" checked><span id="c1Value"></span> 
         </td> 
        </tr> 
       </table>  
      <hr> 
      </div> 
      <input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" > 
      <div class="text-center"> 
       <button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button> 
      </div> 
      <hr> 
     </form> 
     <script language=javascript> 
      function setValue() 
      { 
       var formHtml=$("#formHtml"); 
       $("#formHtml input").each(function() 
                { 
                 //console.log($(this).attr("name")+","+$(this).val()); 
                 itemName="#"+$(this).attr("name")+"Value"; 
                 $(itemName).html($(this).val()); 
                 $(this).remove(); 
                }); 
       $("#formHtmlValue").val($("#formHtml").html());           
      } 
     </script> 
    </body> 
    </html>