javascript - jQuery php variable echo not working -


i have little contact form, ask user calculate , enter correct value in order prevent spam. now, when send button clicked, fire php script, change calculation values. echo these values , show them new placeholder in case of both, success, failure.

$("#send_button").click(function() {          var url = "contact.php"; // script handle form input.          $.ajax({                type: "post",                url: url,                data: $("#contact_form").serialize(), // serializes form's elements.                success: function(data)                {                    var txt = "<?php echo 'spam protection: calculate ($first_num + $second_num) x $multiplier';?>";                    $("#form_info_label").css('color','#0ed68d');                                                       $("#form_info_label").text(data);                    $("#user_answer").attr("placeholder",txt);                 },                error: function(data) {                      var txt = "<?php echo 'spam protection: calculate ($first_num + $second_num) x $multiplier';?>";                    alert(txt);                    $("#form_info_label").css('color','#f2275e');                    $("#form_info_label").text("error. please try again.");                    $("#user_answer").removeattr('value');                    $("#user_answer").attr("placeholder",txt);                 }                 });          return false; // avoid execute actual submit of form.     }); 

however placeholder ends not interpreting php code, copies text. placeholder ends displaying:

<?php echo 'spam protection: calculate ($first_num + $second_num) x $multiplier';?> 

i ended returning json-encoded array desired values php javascript , parsed response there.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -