JSFiddle - React, Tailwind, and code Playground
by FishBasketGordo
HTML
<div class="input string optional">
<label for="company_navn" class="string optional">Name</label>
<input type="text" size="50" name="company[navn]" maxlength="255" id="webhost_navn" class="string optional">
</div>
<div id="greenDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:green;">
</div>
<div id="redDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:red;">
</div>
<button id="smt">Submit</button>
JavaScript
$(document).ready(function() {
$('#redDiv').click(function() {
$('#webhost_navn').data('myData', 'i');
});
$('#greenDiv').click(function() {
$('#webhost_navn').data('myData', null);
});
$('#smt').click(function() {
var myData = $('#webhost_navn').data('myData'),
val = $('#webhost_navn').val();
if (myData) {
$('#webhost_navn').val(myData + val);
}
});
});