0

I have this one in js file

table = table + '<td class="td-problemlog-div-solution"><input type="button" style="width:40px;  color:White;  background-color:Red;" class="deletetButton" onclick="submitForm()" value="Delete" id="' + obj[i].PROBLEMID + '"/></td>';

It deletes selected row based on confirmation .but here , click cancel and ok doing the same thing , delets the row

and here is the function

function submitForm() {
   return confirm('Rollback deletion of candidate table?');
}

Any help appreciated

xiidea
  • 3,344
  • 20
  • 24
one1day
  • 139
  • 1
  • 3
  • 13
  • I don't really understand what's happening here. Your onclick has submitForm() function, which simply returns true or false. Its not doing anything, so how can you expect a result? – Palash May 15 '14 at 02:43
  • It not hard to understand . But it shows me a pop up and ok or cancel , when i click "ol" it deletes but when i click cancel , it still deletes . – one1day May 15 '14 at 02:47

1 Answers1

2

The onclick will cancel the default behaviour (submitting the form) if there is a return false in it. if you cancel the confirm() you will return a false from submitForm to the onclick. but this means that the onclick function evaluates not to return false but just false. So essentially, you just need to do

onclick="return submitForm()"

Example Fiddle

mfirdaus
  • 4,574
  • 1
  • 25
  • 26
  • Thanks , it will work! – one1day May 15 '14 at 02:54
  • One question . how can i integrate return submitform() in to that html part .Because i tried but it gives me error because of single quotes or double quotes – one1day May 15 '14 at 03:02
  • I'm not sure if this will help but you can use quotes and double quotes in strings by using a \ . example `var string="\""` http://jsfiddle.net/mfirdaus/zC3JT/ – mfirdaus May 15 '14 at 03:44