Check value select option list

I´ve got a wordpress plugin that generates an option list. The generated code is like this:

<select name="question">
  <option value="yes">Yes</option>
  <option value="no">No</option>
  <option value="maybe">Maybe</option></select>

<p id="text">some text</p>

Underneath is a paragraph i like to show if the option maybe is selected. If Yes or No is selected this should be hidden.

The Jquery script i came up with (after lot's of googling, copying and pasting) is this:

$('select').change(function(){
  var selectVal = $(‘select’).val();

            if( $selectVal=="maybe"){
              $('#text').show();}
            else{
            $('#text').hide();}
        });

Unfortunally this doesn't work. Anybody has an idea what i'm doing wrong or how to do it right?

Answers


$('select[name=question]').change(function(){
  var selectVal = $(this).val();

  if( selectVal=="maybe"){
     $('#text').show();
  }else{
     $('#text').hide();}
});

jsfiddle: http://jsfiddle.net/ufomammut66/xqCKD/


$selectVal is different from selectVal. And smart quotes are a no-no in jQuery selectors.

You also need to hide the paragraph onload. CSS display: none can do this best.

http://jsfiddle.net/mblase75/uz2uf/

Incidentally, you can pass a Boolean to the .toggle() method to shorten up your code:

$('select').change(function() {
    var selectVal = $(this).val();
    $('#text').toggle(selectVal=="maybe");
});​

http://jsfiddle.net/mblase75/uz2uf/1/


Need Your Help

Change the escape sequence generated

linux keyboard terminal centos terminfo

This question is a general version of my previous question: Change the escape sequence generated by xterm for key combinations.