简体   繁体   中英

How can I prefill and html form field to send by email?

I have an HTML form with To and From fields, what I would like to do is prepopulate the subject field. Preferably using JS or jQuery.

So the message would read "Hi, thanks for stopping by (the rest of the message)..." similar to how LinkedIn prefills the subject field of a connection request.

I don't think and HTML placeholder would work because that does not get sent with the email.

实现此目的的方法很多,但我只会使用隐藏字段

<input type="hidden" name="subject" value="This is the subject">

You can set a predefined value to your input fields by

<input type="text" value="whatever you want"/> // or <input type="hidden" value="whatever you want">

If it's only static text, there's absolutely no need for javascript.

If you need to alter it depending on the page content, you can access an element like:

<input type="text" id="thisFieldsId"/>
var thisField = document.getElementById('thisFieldsId');
thisField.value = 'whatever you want';

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input

Set the value attribute. If you want the prefilled out part to vanish if they click it in like the placeholder attribute, but actually send the value if they don't change it then you'll need to you some javascript magic to clear it yourself when it gets clicked/focused.

<input type="text" name="subject" value="Some Value">

or if you need textarea instead

<textarea name="subject">Some Value</textara>

Jquery solution:

<input type="text" class="text" value=""/>

$(document).ready(function(){
$('.text').val('hey');
});`

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM