0

I have a problem with submiting data into the django form so basically I have model with the 2 fields which take value 1 or 0 so I Created functions with jquery and I set them into the buttons but when i press double click it submit the value of .click function not the dblClick function.

my code is here in html:

<br>
<button type="submit" id="up_vote_btn">Up Vote </button>
<br>

my jquery code:

<script>

$(document).ready(function(){
 $("#up_vote_btn").click(function(){
   document.getElementById("id_up_vote").setAttribute('value','1');
   document.getElementById("id_down_vote").setAttribute('value','0');
  });
});

$(document).ready(function(){
  $("#up_vote_btn").dblclick(function(){
    document.getElementById("id_up_vote").setAttribute('value','0');
    document.getElementById("id_down_vote").setAttribute('value','0');
   });
});
icy
  • 1,468
  • 3
  • 16
  • 36
Umer
  • 77
  • 1
  • 1
  • 8
  • well a double click is two clicks.... – epascarello Jul 03 '19 at 16:26
  • yes i checked but when you double click it will submit the data of single click into the form fields – Umer Jul 03 '19 at 16:28
  • 1
    because submit button submits on click.... and a double click is two clicks... Browser does not care you bound a double click.... – epascarello Jul 03 '19 at 16:28
  • well what can i do is there any other way to solve this problem? – Umer Jul 03 '19 at 16:30
  • 1
    Try this link https://stackoverflow.com/questions/1067464/need-to-cancel-click-mouseup-events-when-double-click-event-detected – Akhilesh Jul 03 '19 at 16:36
  • 1
    Single click to vote up and double click to reset to 0? Not very intuitive. Why would I even double click on an up arrow at the first place? I suggest doing a toggle, an on/off like action. Click once to upvote, and only IF the upvote is already ON, then clicking the same button would just reset to 0. – Nawed Khan Jul 03 '19 at 17:40
  • @Akhileh i tried but it is the same as i was having with my own function – Umer Jul 03 '19 at 17:56
  • @NawedKhan I had this way because in the database i want when someone double click on the button then in the database i will delete the the object. – Umer Jul 03 '19 at 18:02
  • 1
    Which you can do with my suggestion of toggle too. One click, vote up, create record in database. Another one click, vote down (if vote is up), delete the record in database. It doesn't matter what you are doing in database or in server side code... the issue at hand is double click is not a good option because it is simply 2 single clicks and you have totally 2 different functions assigned to single and double click. – Nawed Khan Jul 03 '19 at 18:06
  • @NawedKhan thank you, i will try with toggle. – Umer Jul 03 '19 at 19:19

0 Answers0