Reputation: 65
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
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.
Upvotes: 7
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
Reputation: 121998
Try
var value =$('#input').val();
var firstLetter=value.substring(1, value.length);
Upvotes: 0