Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Multiple submission problem
Old 01-04-2011, 08:36 AM Multiple submission problem
Super Talker

Posts: 134
Trades: 0
i have some code like this

Code:
    $(".commentsubmit").click(function() {
     if ($(this).prev()[0].value != "") {
      var thiscomment = $(this).parents(".quick_comment_form");
      var cbox = thiscomment.next().next();
      var mbox = thiscomment.find(".commentmessage");
      var tbox = thiscomment.next();
      cbox.html("<img src=\"http://url\" /> Submitting");
      $.post("http://url",
      {message:mbox[0].value,target_id:tbox[0].value},
        function(data){
       cbox.html("");
       cbox.after(data);
       mbox.attr("value","");
       },"html"
      );
      return false;
     }
    });
the problem is that the data sometimes is submitted more than one time.

what to do about this
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-04-2011, 10:14 AM Re: Multiple submission problem
kai_strieder's Avatar
Novice Talker

Posts: 6
Name: Kai Strieder
Location: germany
Trades: 0
This depends on what element-type your submit is bound to.

You should use "event.preventDefault();" within your event handler to cancel any execution of the actual link element.
__________________
:-:
Please login or register to view this content. Registration is FREE

:-:
Please login or register to view this content. Registration is FREE
kai_strieder is offline
Reply With Quote
View Public Profile Visit kai_strieder's homepage!
 
Old 01-04-2011, 10:50 AM Re: Multiple submission problem
Super Talker

Posts: 134
Trades: 0
this is the code

Code:
  <div>
  <a href="#" class="quick_comment">+'.$flag.'</a> | '.$likeit.'
   <div class="quick_comment_form" style="display:none;">
    <table border="0"><tr><td valign="top">
    <img src="'xxxxxxxxx'" width="25" height="25" />
    </td><td>
    <textarea name="message" rows="2" class="fpost commentmessage""  style="width:350px;" ></textarea>
    <input type="button" value=" '.$flag.' " class="fbutton commentsubmit" />
    </td></tr>
    </table>
   </div>
   <input type="hidden" name="wall_id" value="xx'" />
   <div></div>
  </div>';
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 01:04 PM Re: Multiple submission problem
kai_strieder's Avatar
Novice Talker

Posts: 6
Name: Kai Strieder
Location: germany
Trades: 0
You are binding your event handler to both the anchor and the button. in case of the button, you are not preventing the default behaviour of the button.

Change it like that:

Code:
    $(".commentsubmit").click(function(event) {
     if (!event) { event = window.event;}
     if (event.preventDefault) { event.preventDefault();}
     if (event.stopPropagation) { event.stopPropagation();}

     if ($(this).prev()[0].value != "") {
__________________
:-:
Please login or register to view this content. Registration is FREE

:-:
Please login or register to view this content. Registration is FREE
kai_strieder is offline
Reply With Quote
View Public Profile Visit kai_strieder's homepage!
 
Reply     « Reply to Multiple submission problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19227 seconds with 12 queries