Is there anyway to grab the default value of the slider handle if it is not moved?

StackOverflow https://stackoverflow.com/questions/23160633

  •  05-07-2023
  •  | 
  •  

I am using JQuery UI sliders in a mobile survey application. I can correctly capture the slider value if the label is clicked or the handle is moved to the label. My problem is that if the user does not click on a label/move the slider. I want to record the initial value of the slider. Here is the html where the slider goes:

<div class="well-lg">
    <b>@Html.DisplayFor(model => model.QuestionsText)</b><div id="mySlideOutput"></div>
    <br />
    <div id="mySlideOutput"></div> // testing output of slider value
    <br />
    @*Include ID of EvaluationQuestion in ID of slider*@
    <div id="slider-@(Model.ID)"></div>
    @Html.Hidden("QR-" + @Model.ID)
</div>

Here is the Jquery code:

<script>
var items = ['Very Exceptional Results', 'Above Standard', 'Standard', 'Results Not Acceptable', 'Less Than Standard', 'N/A'];

@*var sliderDefault = $("#slider-@(Model.ID)"),
    initialValue = 1;*@

// commented out code that was used to make sure the value is being populated at certain states

//NOTE:  Needs to be changed to populate slider item labels from database.
$("#slider-@(Model.ID)").slider({
    value: initialValue,
    min: 1,
    max: 6,
    //step: 1,
    slide: function (event, ui) {
        $("#QR-@(Model.ID)").val(ui.value);
        $('#mySlideOutput').html('ui-value = ' + ui.value);
    },

    @*stop: function(event, ui) {
        $("#QR-@(Model.ID)").val(ui.value);
        //alert(ui.value);
    },*@

    @*start: function(event, ui) {
        $("#QR-@(Model.ID)").val(ui.value);
        alert(ui.value);
    }*@
});

$("#slider-@(Model.ID)").slider("pips", { rest: "label", labels: items });

I would like the initial value to populate the db if the slider is not moved to another option. Any suggestions? I appreciate the help.

有帮助吗?

解决方案

$("#slider-@(Model.ID)").slider("value");

This will just return the value of the slider at any time it is called... whether you want to call this function at run time, or just before page unload is up to you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top