I'm working on a project, what i simply want to do is create an html form for posting reply but if the user is too lazy to reply he/she can just click auto-generate ment and a text is directly inserted on the form and automatically posted afterwards..
I'm working on a project, what i simply want to do is create an html form for posting reply but if the user is too lazy to reply he/she can just click auto-generate ment and a text is directly inserted on the form and automatically posted afterwards..
Share Improve this question asked Feb 17, 2016 at 7:18 Tunero_UchihaTunero_Uchiha 531 silver badge5 bronze badges 3- Have you tried anything before asking question? – Vicky Gonsalves Commented Feb 17, 2016 at 7:34
- 2 Wele to SO. Please visit the help center to see what and how to ask. HINT: Post code of what you tried – mplungjan Commented Feb 17, 2016 at 7:34
- You also can use Microsoft Outlook Reply with Template Add-in – Muhammad Muazzam Commented Feb 17, 2016 at 8:01
4 Answers
Reset to default 4$( "#lazybutton" ).click(function() {
$('#inputBox').val("Hey I feel too lazy to type"); // filled automatically in input box
setTimeout(function(){
$('#form').submit(); //submitting form
}, 2000);
});
added sleep time so users can see input box for 2 sec after filled it.
Assuming you want to execute at client site.
create a Array/String of predefined answer and create a click handler of Posting button then insert predefined answer to ment box and post it.
$(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
});
});
Using jQuery, the input can be populated using .val()
then submitting the form using .submit()
which will be the same as the submit button being clicked.
$(document).on('click', '#autogen', function(){
$('#myTextarea').val('Some ment here');
$('#myForm').submit();
});
<script src="https://ajax.googleapis./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>
Reference: jQuery Documentation
For this, first, you should generate the text and append the generated text to ment field. But after I'm not sure what do you want as asking for "automatically posted". Do you want to post the form as like normally pressing the submit button? If yes, you may use the below code as logic.
$("button#lazyGenerate").on("click", function(){
var generatedText = "bla bla and bla";
$("#yourCommentField").val(generatedText);
$("input[name='submitButtonName']").click();
});