Chee mun Low
Chee mun Low

Reputation: 138

looking for method to check string that contains some word

i am doing dynamic tooltip, basically what i am trying to achieve is to detect multiline tooltips, if my data inside contains \r, then i will perform some action, the code below is a sample that i am trying to check my description, but i failed.

Note: My main object is to check the contains of my description

<script type="text/javascript">
// description
var data = {
    name: "enter your name",
    family: "enter your \r family",
    uc2_txtname: "enter your name for Control 2 (User Control2)",


}
function Show(){
var text = '';
// failed to check my above data , the data.contains('\r') is not working
        if (data.contains('\r')) {
            text = 'good';
        } else {
            text = 'bad';
        }
}

</script>

Upvotes: 0

Views: 177

Answers (1)

zz3599
zz3599

Reputation: 647

You should use indexOf instead of contains (javascript has no support for that function).

function Show(){
    var text = '';
    for(var d in data){
        var val = data[d];
        if (val.indexOf('\r') != -1) { 
            text = 'good';
        } else {
            text = 'bad';
        }
    }
}        

Upvotes: 3

Related Questions