Thursday, March 14, 2013

Re: ajax submit and reset form after submission

hi chetan,... 
I have another problem with comments report form,... each comments is got its own ID,... I can't clear the form with unique ID after submission,... is there another way to do this,...? it's ONLY reset last comment submission,... say if I have 9 comments in the raw, it's reset the 9 one,... but not 1,2,... or 8,...  please help,... thanks in advance,... 

here is my form: 

<div id="updateReportPhotoComment_<?php echo $photo_comment['PhotoComment']['id'] ?>" 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('PhotoComment', array('id'=> "ReportComments_".$photo_comment['PhotoComment']['id'])); ?>
    <?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', array('rows' => '4')); ?>
      </p>

    <p>
<?php echo $ajax->submit('Report', array('url'=> array('controller'=>'photo_comments', 'action'=>'report_spam/'. $photo_comment['PhotoComment']['id']), 'update' => "updateReportPhotoComment_".$photo_comment['PhotoComment']['id'], 'complete' => 'javascript:resetReportPhotoCommentForm();' )); ?>
<?php echo $form->end(); ?>
    </p>

</div>


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


and here is the script: 

<script>
function resetReportPhotoCommentForm()
{

            $('#ReportComments_<?php echo $photo_comment['PhotoComment']['id'] ?>').each(function(){
                this.reset();  

// document.getElementById("ReportComments_<?php echo $photo_comment['PhotoComment']['id'] ?>").reset();

            });

}
</script>

Sincerely, 
Chris


On Thursday, October 25, 2012 1:13:20 AM UTC-7, chetan varshney wrote:
You can call javascript function on complete


<?php echo $ajax->submit('Add', array('url'=> array('controller'=>'photo_
comments', 'action'=>'ajax_add/'. $photo['Photo']['id'] ), 'update' => 'updateDiv', 'complete' => 'javascript:resetThisForm();')); ?>
 
<script>
function resetThisForm()
{
document.getElementById("FormId").reset();
}
</script>

On Thu, Oct 25, 2012 at 1:15 PM, Chris <chri...@yahoo.com> wrote:
hi guys,... is there a way to reset form after ajax submission...? or do I have to go thru jquery submission? 
here is my form: 

<?php echo $this->Form->create('PhotoComment'); ?> 
    <?php echo $form->hidden('user_id', array('value' => $user_object['id'])) ?>
<?php  echo $this->Form->textarea('content', array('rows' => '3')); ?>

<?php echo $ajax->submit('Add', array('url'=> array('controller'=>'photo_comments', 'action'=>'ajax_add/'. $photo['Photo']['id'] ), 'update' => 'updateDiv')); ?> 

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

<div id="updateDiv" style="margin: 10px 0 10px 0;"></div> 

thanks in advance 
chris 


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to cake-php+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 



--
Chetan Varshney
Ektanjali Softwares Pvt Ltd

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: