David
David

Reputation: 972

input.value is returning undefined

Input:

<input type="radio" name="options" id="onetime" autocomplete="off" value="90" class='planSelect'> One-Time 6 Months

jQuery:

$('.planSelect').value;

This is returning "90undefined" and I have no idea why?

Upvotes: 0

Views: 75

Answers (1)

Robert I
Robert I

Reputation: 1527

$('.planSelect') returns a jQuery selector, use .val to access its value

Use $('.planSelect').val(); instead.

let index = 0;
let randomColors = ["red","green","blue"];

function run(){
     $("#result").text($('.planSelect').val()).css("color",randomColors[index++%3]);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="options" id="onetime" autocomplete="off" value="90" class='planSelect'> One-Time 6 Months
<div> Result: <span id="result"></span></div>
<button onclick="run()">Rerun</button>

Upvotes: 2

Related Questions