0

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?

1
  • Pre-loading the prices isn't very elegant, imho. The answer to your first question is 'yes' (someone does know how). See answers below ;) Commented Aug 10, 2011 at 18:58

3 Answers 3

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

Or, if you want the value...

$('#selectID').change(function() {
    $('#divID').text($(this).val());
});
Sign up to request clarification or add additional context in comments.

1 Comment

That would be simpler. I did it the way I did because I copied the text example.
1

You could do something like this:

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

Example

4 Comments

You beat me to it! Don't forget the closing paren.
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 }
@gilly3 Fixed it before you wrote this comment :) But thanks for pointing out.
@mkk well, you could use .html(), but it doesn't matter really. For plain text I really prefer using .text()
0

What about this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.