How to get the first value from a word entered in the input (only the first letter)

I know this question is so noob. but I want to know how to get the first letter of the entered word in the input text.

I do not know about that. but please tell me about it.

+4
source share
3 answers

The built-in Javascript substr() method can do this:

 var firstChar = $('#textbox').val().substr(0, 1); 

The first argument is the position of the character to begin with, the second is the length.

MDN Documents

+6
source

You can use charAt to get the first letter.

 var x = 'some text'; alert(x.charAt(0)); 

If you use jQuery and have a text field with id = "firstName", you can access the first letter as follows.

 var firstLetter = $("#firstName").val().charAt(0); 
+3
source

Try

 var value =$('#input').val(); var firstLetter=value.substring(1, value.length); 
0
source

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


All Articles