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?
3 Answers
$('#selectID').change(function() {
$('#divID').text($(this).find(':selected').text());
});
Or, if you want the value...
$('#selectID').change(function() {
$('#divID').text($(this).val());
});
1 Comment
FishBasketGordo
That would be simpler. I did it the way I did because I copied the
text example.You could do something like this:
$('#select').change(function() {
$('#price').text($(this).val());
});
4 Comments
gilly3
You beat me to it! Don't forget the closing paren.
mkk
I believe you meant $('#price') not #div. For divs I use to use .html() instead of .text(), but maybe both of them works :) moreover you have typo in brackets, it should be }); not just }
Madara's Ghost
@gilly3 Fixed it before you wrote this comment :) But thanks for pointing out.
Madara's Ghost
@mkk well, you could use
.html(), but it doesn't matter really. For plain text I really prefer using .text()