jquery - How to force user to input value in javascript prompt? -


i have jquery code, open prompt box. problem whether user inputs value in or not, still proceeds code if user click ok. there anyway force user input value in, click ok else can not click ok button.

here tried did not work.

$(function() { $(".adminapprovepost").click(function(){ var id = $(this).attr("id"); var tag = prompt("you must enter 1 keyword approve post"); if(tag!=null) {   $.ajax({   type: "post",   url: "/admin/admin-approve-post.php",   data: {id:id,tag:tag},    success: function(){    }   });  $(this).parents(".postrecord").animate({ backgroundcolor: "#fbc7c7" }, "fast") .animate({ opacity: "hide" }, "slow"); } return false; }); }); 

it should work this:

$(function() {     $(".adminapprovepost").click(function(){         var id = $(this).attr("id");         var proceed = true;         while(proceed) {             tag = prompt("you must enter 1 keyword approve post");             if (typeof(tag) == "string") {                 tag = tag.trim()                 if (tag!="")) {                     proceed = false;                 }             }             if (tag===null) {                 proceed = false;             }         }         if(tag!=null)         {             $.ajax({                 type: "post",                 url: "/admin/admin-approve-post.php",                 data: {id:id,tag:tag},                 success: function(){                 }             });             $(this).parents(".postrecord").animate({ backgroundcolor: "#fbc7c7" }, "fast")             .animate({ opacity: "hide" }, "slow");         }         return false;     }); }); 

edit: user can click 'cancel'. , should work. (i hope…)


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -