php - MYSQL subtract value if input differs -


i have text area (txt_description) on form used calculate score. score weighted follows: if input in text area smaller 75 words, 5 points added col_score column(tinyint(1) in tbl_score table of database. if input in text area greater 75 words, 10 points added col_score(tinyint(1) column in tbl_score table of database. onblur event calls jquery script 'counts' words , sends add_score.php page handles update event. code below:

if (isset($_post["txt_description"]));  {       $sessionscore = $_post["txt_description"]; // ◄■■ parameter ajax.       if ($sessionscore <= 75) {         $descscore = 5;     } else if ($sessionscore >= 75) {                $descscore = 10;                     }     $updatesql=sprintf("update tmp_score                              set col_score=col_score+%s                          sessionid = %s",                     getsqlvaluestring($descscore, "int"),                     getsqlvaluestring($_session['sessionid'], "text")                     );                      $result=mysql_query($updatesql) or die(mysql_error());            }   

it works well, cannot figure out how update score if user goes , make changes text in text area?

with other words, if user changes mind answer , goes , change answer shorter or longer one? meaning value change 5 10 or vise versa.

please help. hair thinning second :-)

i think need use onchange jquery event , send ajax request every time user change value. ajax request this

jquery(document).ready(function($){ $(document).on("change","#textareaid",function(){   $.ajax({type: "post",     url: 'yoururl', //ajax request url here     data:{}, // data update here     success: function(data) {        //do response here       }    }); });  }); 

i hope out.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -