javascript - Adding a plus "+" symbol to positive numbers in a JQuery output -
i have modified jquery ui slider bar (-100 +100). when user moves slider , down scale receive visual feedback via <div id="slider-result"></div>
currently slider-result
displays -
symbol when number negative e.g. -47
, not display +
symbol when number positive e.g. 61
how can make slider-result
display +
symbol before number when positive?
i have looked @ question when try integrate solution displays +
when number positive, stops displaying number...
my attempt
slide: function(event, ui) { $("#slider-result").html(ui.value>0?'+':'') + ui.value;
any helps always, appriciated. thanks
edit - complete code
$('#submit').click(function() { var username = $('#hidden').val(); if (username == "") username = 0; //should still 0? $.post('comment.php', { hidden: username }, function(return_data) { alert(return_data); }); }); $(".slider").slider({ animate: true, range: "min", value: 0, min: -100, max: +100, step: 1, slide: function(event, ui) { $("#slider-result").html(ui.value>0?'+':'') + ui.value; //this updates hidden form field can submit data using form if($(this).attr("id") == "one") $("#hidden1").val(ui.value); } });
you have include + ui.value;
inside of parentheses well:
$("#slider-result").html((ui.value>0?'+':'') + ui.value);
since have '+'
or ''
inside of html()
method, put values , not include actual value.
Comments
Post a Comment