image:
result:
I have a problem that the submit button (reply button) is not disabled after i press '(single quote) or many of them, I just want it disabled. The point is preventing someone type a single/double quote or a weird character on the textarea. I have a code from someone in here and it works in testing in a different file, but here the condition is different, the form is inside an ajax and I'm very newbe in Jquery, and i don't know where to put that code to make it works.
this is my simple code of ajax:
var x;
function clickreply(obj){
var varid = obj.id;
var getnumb = varid.match(/\d/g); //get number from string
var idreply = 'idreply'+getnumb;
console.log(varid);
console.log(getnumb);
console.log(idreply);
$.ajax({
url: '/logincheckmember2.php', //This is the current doc
type: "POST",
dataType:'json', // add json datatype to get json
success :
function (result) {
x=result['ssloginmember'];
console.log(x);
if(result['ssloginmember']==null){
msgBLshow();
}else{
x="<center>"+
"<form method='post' name='myForm' id='myForm'>"+
"<textarea id='tareply' rows='4' cols='50' maxlength='250' placeholder='maxlength=250'></textarea><br>"+
"<input type='submit' id='submitreply' value='reply' onclick='clicktareply()'></input>"+
"</form>"+
"</center>";
document.getElementById("msgcontent1").innerHTML=x;
$("#msg1").fadeTo(1000, 1);
}
}
});
}
function clicktareply(){
alert(document.getElementById("tareply").value);
}
$(document).ready(function() {
$('#tareply').keyup(function() {
if(!$(this).val().match(/^(?!\s)([a-zA-Z0-9 _.)?&]){1,}$/g)) {
$('#submitreply').prop('disabled', true);
}else{
$('#submitreply').prop('disabled', false);
}
});
});