Reputation:
This is simple even though i don't know why i don't get it to work. I just need the value of the text field. Here is the code. http://jsfiddle.net/VL8hr/
$(document).ready(function() {
var firstname = $('.firstname').val();
alert(firstname);
});
Upvotes: 2
Views: 99
Reputation: 6554
You selector is wrong. You have used id attribute, but in your javascript code you tends to use it as a class. It should be like this
$(document).ready(function() {
var firstname = $('#firstname').val();
alert(firstname);
});
you can differentiate between id and class selector over here.
http://api.jquery.com/id-selector/
http://api.jquery.com/class-selector/
Upvotes: 1
Reputation: 2711
#
is selector for id
and .
is selector for class
.
$(document).ready(function() {
var firstname = $('#firstname').val();
alert(firstname);
});
Upvotes: 1
Reputation: 125
Change your jquery
$(document).ready(function() {
var firstname = $('#firstname').val();
alert(firstname);
});
Upvotes: 0
Reputation: 388316
You need to use id-selector instead of class-selector since firstname
is the id
of the element
var firstname = $('#firstname').val();
Demo: Fiddle
Upvotes: 3