How to add text to form input
I am really not sure where to start with this. I have a form input box and submit button. When the submit button 开发者_运维百科is pressed, the form content is submitted and used in some javascript. What I want to do is automatically add some text to the end of the submission.
So if a user inputs "The dog walked" and pressed submit, the form would add "across the street." to the end of the submission.
Thank you!!
In your event listener for the form's submit action, change the input.
document.getElementById('theinputid').value = document.getElementById('theinputid').value + "across the street."
W3 schools is your friend: Form onsubmit Event
So in your case it's something similar to:
<script type="text/javascript">
function addText() {
var input = document.getElementById('something');
input.value = input.value +' across the street';
}
</script>
<form name="frm1" action="?" onsubmit="addText()">
<input type="text" name="somehting" id="something" />
<input type="submit" value="Submit" />
</form>
You Can Use +=
, for instance:
input.value +=
精彩评论