2013-10-31 75 views
0

我有一個表單(報表),它在頁面上多次鏈接到jquery對話框。我添加了隨機字符串以避免交叉發送(提交)。我想在提交後清除表單(ReportContent)字段,並有一點問題。然而,它在下面第二個腳本的單頁訪問提交中工作正常。請幫幫忙,...在此先感謝...克里斯在cakephp 1.3中提交後的清晰表格

<?php echo $ajax->form(array('type' => 'post', 'options' => array('model'=>'Group', 'id'=> "submitThis_".$random, 'update' => "updateGroupReport_".$group['Group']['id']. '-'.$random, 'complete' => 'javascript:resetReportGroupForm(' . $random . ');', 'url' => array('controller' => 'groups', 'action' => 'report/'. $group['Group']['id'])))); ?> 
<?php echo $this->Form->textarea('Report.content', array('class' => "ReportContent_".$random)); ?> 
<?php echo $form->end('Report'); ?> 

此我要工作,...

<script type="text/javascript"> 
function resetReportGroupForm($id){ 
    document.getElementById("submitThis_<?php echo ($random); ?>"), function() { 
     $('.ReportContent_<?php echo ($random); ?>').val(''); 
     }; 
    }; 
</script> 

能正常工作的單頁訪問,...

<script type="text/javascript"> 
function resetReportGroupForm($id){ 
    document.getElementById("submitThis_<?php echo ($random); ?>").reset(); 
    } 
</script> 

回答

0

爲什麼不嘗試這樣的事:

$('form#submitThis_<?php echo $random?>').find("input[type=text], textarea").val(""); 

我覺得你應該使用jQuery選擇重置您的形式,雖然不是......

$('form#yourFormName').submit(function() { 
    // process ajax etc 

    $(this).find("input[type=text], textarea").val(""); 
}); 
0

我有另一種方法是,......其做工精細,...這是合同複印件,如果任何人需要它,...

<div class="clr"></div> 

<div id="updateGroupReport_<?php echo $group['Group']['id'] ?>-<?php echo $random ?>" style="float: left; width: 200px; margin: 5px 0 5px 15px; font-size: 13px; text-align: left;"></div> 

<div class="clr"></div> 

<div style="float: left; width: 450px; margin: 0 0 20px 15px; font-size: 13px; text-align: left;"> 

<?php echo $this->Form->create('Group', array('id'=> "FormId_".$random)); ?> 
    <?php echo $form->hidden('Report.sender_id', array('value' => $user_object['id'])) ?> 

    <p style="font-size: 1.2em; font-weight: normal;"> 
<?php echo $this->Form->textarea('Report.content'); ?> 
    </p> 

    <p> 
<?php echo $ajax->submit('Report', array('url'=> array('controller'=>'groups', 'action'=>'report_spam/'. $group['Group']['id']),'id' => "button_".$random, 'update' => "updateGroupReport_".$group['Group']['id']. '-'.$random)); ?> 
<?php echo $form->end(); ?> 
    </p> 

</div> 

<script type="text/javascript"> 
jQuery(document).ready(function() { 
    $('#button_<?php echo ($random); ?>').click(function(){ 
      $(':input', '#FormId_<?php echo ($random); ?>') 
     .not(':button, :submit, :reset, :hidden') 
     .val('') 
     .removeAttr('checked') 
     .removeAttr('selected'); 
     }); 

}); 
</script> 

<div class="clr"></div>