Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!!

like image 299
Brandon Avatar asked Jul 16 '11 00:07

Brandon


People also ask

How do you put text in a form?

Open the form or report in Design view by right-clicking the form or report in the Navigation Pane, and then clicking Design View. On the Design tab, in the Controls group, click Text Box. Position the pointer where you want the text box to be placed on the form or report, and then click to insert the text box.

How do you input text in HTML?

To sum up, to create a text input field in HTML, you need at least: An <input> element, which typically goes inside a <form> element. To set the type attribute to have a value of text . This will create a single line text input field.

How do you style text inside input field?

If you only want to style a specific input type, you can use attribute selectors: input[type=text] - will only select text fields. input[type=password] - will only select password fields. input[type=number] - will only select number fields.


2 Answers

In your event listener for the form's submit action, change the input.

document.getElementById('theinputid').value = document.getElementById('theinputid').value + "across the street."
like image 179
Dan Grossman Avatar answered Oct 01 '22 12:10

Dan Grossman


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>
like image 29
Sascha Galley Avatar answered Oct 01 '22 12:10

Sascha Galley