# in input automatically and css to give it blue color

1

Good friends, I have a form which I want to send by email using phpmailer, and that part is running, the one that has come up is that I want to add to the words that I enclose by writing in the "tags" a prefix #

if I write juan that the same one is transformed into #juan and that when pressing another key of letter or that is not space I generate a #a

then add that to the css to see it blue to impact Where can I start?

<form class="form-horizontal" method="POST" action="addEvent.php">
<div class="form-group">
                    <label for="etiquetas" class="col-sm-2 control-label">Etiquetas</label>
                    <div class="col-sm-10">
                      <textarea  name="etiquetas" class="form-control" id="etiquetas" placeholder="escriba y separe con espacio las etiquetas a usar" required onkeyup="mayus(this);"></textarea>
                    </div>
                  </div>
    <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">Cerrar</button>
                <button type="submit" class="btn btn-primary">Guardar</button>
              </div>
            </form>
    
asked by Juan Ortiz 28.06.2018 в 17:40
source

1 answer

2

This is as close as I could get.

function mayus(texto) {
  var text = texto.value.replace('#', '');
  var words = text.split(" ");
  var newTexto = "";
  for(var i = 0; i < words.length; i++) {
      if (words[i].length > 0) {
        newTexto += "#" + words[i];
      } else {
        newTexto += " ";
      }
  }
  
  texto.value = newTexto;
};
<form class="form-horizontal" method="POST" action="addEvent.php">
<div class="form-group">
                    <label for="etiquetas" class="col-sm-2 control-label">Etiquetas</label>
                    <div class="col-sm-10">
                      <textarea  name="etiquetas" class="form-control" id="etiquetas" placeholder="escriba y separe con espacio las etiquetas a usar" required onkeyup="mayus(this);" style="color: blue;"></textarea>
                    </div>
                  </div>
    <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">Cerrar</button>
                <button type="submit" class="btn btn-primary">Guardar</button>
              </div>
            </form>
    
answered by 28.06.2018 в 18:03