Terry
Terry

Reputation: 37

Changing values in Javascript

I'm new to Javascript and I'm trying to learn by tinkering with a webpage. So it is a button and when you click it, it gains a child with the id oddsInput. I cant get the values to change

function checksettings(payout) {
$('#oddsPayout').click();
var iodds = $('#oddsInput');
iodds.value = payout;
// $('glyphicon glyphicon-ok btn btn-success').click();
}

checksettings(2)

Upvotes: 4

Views: 30

Answers (2)

Waqas Shahid
Waqas Shahid

Reputation: 1060

Try

$('#oddsInput').val(payout);

Upvotes: 0

Josh Crozier
Josh Crozier

Reputation: 240868

It's because $('#oddsInput') is a jQuery object. It doesn't have a value property.

Either access the first DOM element in the jQuery object:

iodds[0].value = payout;
// or
$('#oddsInput')[0].value = payout;

or, since it's a jQuery object, use the .val() method:

iodds.val(payout);
// or
$('#oddsInput').val(payout);

Upvotes: 2

Related Questions