Reputation: 14824
I'm simply trying to use whatever is typed into the <input type="text">
as a variable for my script.
I've tried .select() .value() .val() and it keeps returning undefined or null. I'm trying to do it async so the page doesnt have to refresh but it doesn't want to work as I intend.
$(function() {
$('#changeDistance').click(function(e) { e.preventDefault();
console.log('Triggered');
setDistance = $('#setDistance').select();
console.log($('#setDistance').select());
for (var i = 0; i < markersArray.length; i++) {
markersArray[i].setMap(null);
}
for (var i = 0; i < database.length; i++) {
createMarker(database[i].latitude, database[i].longitude, database[i].markerTitle, initialLocation);
}
});
});
is where I'm trying to use it
Upvotes: 0
Views: 121
Reputation: 4701
First you need to specify and Id
to your input tag
Use this
$('#inputID').val()`
With ID you need to use #
and if you specify a class then you need to use period .
If you give class (class is assigned to many attribute) then you will get array. So you need to access each element by index
$('.classname').each(function() {
$(this).val();
});
Upvotes: 2
Reputation: 4273
you can use by Textbox id
$("#TextboxId").val();
or
$("input[type='text']").val();
or
$(".text-classname").val();
Upvotes: 0
Reputation: 324650
Assuming your input is indeed as follows: <input type="text" id="setDistance" />
then the correct function to get its value in jQuery is .val()
.
However, if you write $("#setDistance").val()
then I will lynch you. Use document.getElementById('setDistance').value
instead.
Upvotes: 4