Louis Stephens
Louis Stephens

Reputation: 790

Using jquery to display value

I have a form with a select currently in use and an empty div (#price) below the form . I was wondering if anyone knew how (using jquery), to make it so that if I chose something in the select, to output it to the box. Or is the best solution to have the prices already loaded into the empty div, and just hide them using css?

Upvotes: 0

Views: 74

Answers (3)

FishBasketGordo
FishBasketGordo

Reputation: 23132

$('#selectID').change(function() {
    $('#divID').text($(this).find(':selected').text());
});

Or, if you want the value...

$('#selectID').change(function() {
    $('#divID').text($(this).val());
});

Upvotes: 1

Madara's Ghost
Madara's Ghost

Reputation: 174957

You could do something like this:

$('#select').change(function() {
    $('#price').text($(this).val());
});

Example

Upvotes: 1

Im0rtality
Im0rtality

Reputation: 3533

What about this:

$("#select-id").change(function() {
  $("#price").text($("#select-id").val());
});

Upvotes: 0

Related Questions