I want to create an input text field that does not require a form element

Create an input text field without using <input type = "text">

I want to create an input text field that does not require a form element <input type="text"> . The user can still enter text into this text box, and the value can still be obtained using Javascript / jQuery. The reason for this is that this text field will be in the form, which when sending all the input values โ€‹โ€‹of the form will be sent to the server side for processing, and there is this text field that I do not want its values โ€‹โ€‹to be automatically sent to the server side.

Problem: What is the best way to create such a text field without using HTML input form elements?

+4
source share
6 answers

Just do not specify the tag <input type="text"> a name and it will not be sent. Here is an example:

 <input type="text" id="myinput" value="you will not see this submitted" /> 
+9
source

You can also use contenteditable div.

From MDN:

 <!DOCTYPE html> <html> <body> <div contenteditable="true"> This text can be edited by the user. </div> </body> </html> 

http://html5demos.com/contenteditable

+5
source

if you create a dynamic <input type="text"> using jQuery, it will return its values.

What bothers you if its values โ€‹โ€‹are sent back? just do nothing with them on the server side.

or,

before sending - change the input type to the label. (+ save values)

or,

if you add the OUTSIDE input to the FORM element, it will not send.

+1
source

you can use textarea instead of input . then apply css. You can also use your input tag, just keep it outside the <form></form> , after which it will not be sent to the server.

+1
source

just create an input and donโ€™t give it a name or id .

+1
source
 $("#form").bind('submit', function() { $(this).children('input[name=excludethisfield]').attr('disabled', true); }); 

I know that this is not what you requested, but may be the easiest way.

+1
source

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


All Articles