admin管理员组文章数量:1414892
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();
});
本文标签: javascriptHow to auto insert text in an html form and auto submit itStack Overflow
版权声明:本文标题:javascript - How to auto insert text in an html form and auto submit it? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745186893a2646726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论