jQuery UI: how to run evaluation

Posted by mikkelbreum on Stack Overflow See other posts from Stack Overflow or by mikkelbreum
Published on 2010-06-16T08:31:18Z Indexed on 2010/06/16 8:42 UTC
Read the original article Hit count: 158

I want to add 'Year' or Years' to the end of a string depending on the string. Like this:

$("#selector").val(conditional_value_here);

Using jQuery UI I have a slider that manipulates a value:

$("#slider").slider({
    value: 1,
    min: 1,
    max: 25,
    step: 1,
    slide: function(event, ui) {
        $("#amount").val(ui.value + ' Year' + function(){return (ui.value == 1) ? '' : 's';} );
    }
  });

// and again I want to do the same for the initialization of the value:
$("#amount_3").val($("#slider_3").slider("value") + ' Jahr' + function(){return ($("#slider_3").slider("value") == 1) ? '' : 's';});

This does not work. What is the correct way to to this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery