Note that there are some explanatory texts on larger screens.

plurals
  1. POthe jquery unbind events makes the function work once but event is repeated
    text
    copied!<p>this is my main page where i have radio button which when clicked a value will be passed via ajax and the result is checked by ajax and the corresponding output is displayed for each question correct/Incorrect. And the problem is my unbind event is working fine once i click on radio button answer is checked and result is displayed and nothing happens when i click again but the problem is click event is not removed i can click again and again thought the function is working fine and only once. </p> <p>So how do i make it not click able once clicked ,where is the problem </p> <pre><code>&lt;!doctype html&gt; &lt;head&gt; &lt;link href="&lt;?php echo base_url('css/style.css');?&gt;" type="text/css" rel="stylesheet"/&gt; &lt;script src="&lt;?php echo base_url('javascript/jquery.js');?&gt;" rel="javascript" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt; &lt;div id="main-content"&gt; &lt;?php foreach($result as $rows):?&gt; &lt;form&gt; &lt;div class="question-box"&gt; &lt;?php echo '&lt;h1 class="Qbanner"&gt;Q.&lt;/h1&gt;'.'&lt;h2&gt;'.$rows-&gt;question.'&lt;/h2&gt;&lt;/br&gt;';?&gt; &lt;input type="radio" name="&lt;?php echo $rows-&gt;question_id;?&gt;" value="a"&gt;&lt;?php echo $rows-&gt;option1;?&gt; &lt;input type="radio" name="&lt;?php echo $rows-&gt;question_id;?&gt;" value="b"&gt;&lt;?php echo $rows-&gt;option2;?&gt; &lt;input type="radio" name="&lt;?php echo $rows-&gt;question_id;?&gt;" value="c"&gt;&lt;?php echo $rows-&gt;option3;?&gt; &lt;input type="radio" name="&lt;?php echo $rows-&gt;question_id;?&gt;" value="d"&gt;&lt;?php echo $rows-&gt;option4;?&gt; &lt;h5 class="result"&gt;&lt;/h5&gt; &lt;/div&gt; &lt;/form&gt; &lt;?php endforeach;?&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- wrapper div ends --&gt; &lt;script&gt; $(document).ready(function(){ var clickedval,qid; $("input:radio").bind('click',function(e){ clickedval=$(this).val(); qid=$(this).attr('name'); var siteurl='&lt;?php echo site_url();?&gt;' + '/site/checkAnswer'; $this=$(this).parent("div.question-box"); $allradio=$(this).parent("div.question-box").children(); $.ajax({ url:siteurl, dataType:'json', type:'post', data:{'answer':clickedval,'questionid':qid}, success:function(data){ $this.find('.result').html(data.resultstatus); $allradio.unbind('click'); } }); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload