How to automatically insert text in html form and send it automatically?

I am working on a project, I just want to create an html form to send a response, but if the user is too lazy to respond, he can just click on auto-generate a comment, and the text will be inserted directly on the form and will be automatically sent subsequently.

+4
source share
4 answers
$( "#lazybutton" ).click(function() {
  $('#inputBox').val("Hey I feel too lazy to type"); // filled automatically in input box        
    setTimeout(function(){
      $('#form').submit(); //submitting form
    }, 2000);
});

sleep time has been added so that users can see the input window for 2 seconds after filling it.

+4
source

Assuming what you want to accomplish on a customer site.

Array/String "", .

$(document).ready(function () {
    var RandComment= ["First Random Comment","Second Random Comment","Third Random Comment"]
    $("#btnSubmit").click(function () {
        var pickRandomComment = RandComment[parseInt(Math.random() * RandComment.length-1)];
        $("#txtCommentBox").val(pickRandomComment);        
        //Call ajax if want to implement

    });
});
+1

. , , , " ". , ? , .

$("button#lazyGenerate").on("click", function(){
  var generatedText = "bla bla and bla";
  $("#yourCommentField").val(generatedText);

$("input[name='submitButtonName']").click();

});
0

jQuery, .val(), .submit(), , .

$(document).on('click', '#autogen', function(){
  $('#myTextarea').val('Some comment here');
  $('#myForm').submit();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<form id="myForm" action="/" method="post">
  <input type="text" id="myTextarea" name="myTextarea">
  <input type="submit" value="Submit">
</form>

<button id="autogen">Generate</button>
Hide result

: jQuery

0

Source: https://habr.com/ru/post/1629111/


All Articles