2

Fiddle

i have a jquery which is for that, if the selected value is "<>"(Between) i want to change the style to display:block to an input box .. but here all the selected items css is changed

$(document).ready(function () {
    $('.condition-change').change(function () {
        if ($('select[name="SearchCondition"]').find('option[value="<>"]').attr("selected", true)) {
            $('.second-value').css("display", "block");
        }
    });
});

4 Answers 4

1

Wrong condition

$(document).ready(function () {
$('.condition-change').change(function () {
    if($('select[name="SearchCondition"]').find('option[value="<>"]').prop("selected")==true)
    {
        $('.second-value').css("display", "block");
    }

});

});
Sign up to request clarification or add additional context in comments.

Comments

1

You simply need to access the selected option value which you can get using val(), so put condition on val(),

Live Demo

$(document).ready(function () {
    $('.condition-change').change(function () {
        if ($(this).val() == "<>") {
            $('.second-value').css("display", "block");
        }
    });
});

Also using show and hide instead of setting css.

Live Demo

$(document).ready(function () {
    $('.condition-change').change(function () {
        if ($(this).val() == "<>") 
            $('.second-value').show();
        else
            $('.second-value').hide();
    });
});

Comments

1

Try,

$('.condition-change').change(function () {
    if($(this).val().trim() === '<>') {
        $('.second-value').show();
    }
});

DEMO

Or

$('.condition-change').change(function () {
    $('.second-value').toggle($(this).val().trim() === '<>');
});

DEMO I

Comments

0

// add .is(":checked") function to check whether "<>" value option is selected

 $(document).ready(function () {
        $('.condition-change').change(function () {
            if($('select[name="SearchCondition"]').find('option[value="<>"]').is(":checked"))
            {
                $('.second-value').css("display", "block");
            }
            else
            {
                $('.second-value').css("display", "none");
            }

        });

      });

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.