convert content into input

Asked

Viewed 62 times

2

Galera use a javascript script to convert everything I type, inside the input to uppercase.

But I have a specific input where I can’t change its content. How can I do this?

Follows the code:

// Converte minusculas em maiusculas
$(document).ready(function() {
  $('input').on('input', function() {

    // Armazena posição corrente do cursor
    var start = this.selectionStart,
      end = this.selectionEnd;
    this.value = this.value.toUpperCase();

    // Restaura posição armazenada anteriormente.
    this.setSelectionRange(start, end);
  });
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<input type='text' name='video'>
<input type='text' name='video'>
<input type='text' name='video'>
<input type='text' name='video'>


<input type='text' name='nao_alterar'>

  • But wherever the text appears in upper case?

  • in all input, except input name='nao_change'

1 answer

0


Create an event executed on all inputs except the one whose name is nao_alterar. Do:

$('input').not('[name="nao_alterar"]').on('input', function() {

// Armazena posição corrente do cursor
var start = this.selectionStart,
  end = this.selectionEnd;
this.value = this.value.toUpperCase();

// Restaura posição armazenada anteriormente.
this.setSelectionRange(start, end);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type='text' name='video'>
<input type='text' name='video'>
<input type='text' name='video'>
<input type='text' name='video'>


<input type='text' name='nao_alterar' placeholder="não alterar">

  • good had to be using the code I posted, because it stores the cursor location.

  • sorry. I’ll do

  • Edited by @Hugoborges

  • very good vlw. Can you check the name backwards? Tupi so it runs for all names except for name='nao_change' ?

  • 1

    might just $('input[name="video"]').on('click', ..., and removed the .not(...)

  • perfect friend, thank you very much.

  • @Hugoborges that’s exactly what I did. All inputs except where the name is "nao_change", $('input').not('[name="nao_alterar"]')...

  • You’re welcome @Hugoborges

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.