janatan
janatan

Reputation: 65

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

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

I don't know about it .but please guide me about that .

Upvotes: 5

Views: 9824

Answers (3)

MrCode
MrCode

Reputation: 64526

The native Javascript substr() method can do that:

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

The first argument is the character position to start from, the second is the length to take.

MDN Docs

Upvotes: 7

Ohlin
Ohlin

Reputation: 4178

You can use charAt to get the first letter.

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

If you're using jQuery and have a textbox with id="firstName" you can access the first letter in the following way.

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

Upvotes: 2

Suresh Atta
Suresh Atta

Reputation: 121998

Try

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

Upvotes: 0

Related Questions