Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery 0 - 10 slider for form question
    primarykey
    data
    text
    <p>trying to create a simple slider for an input.</p> <p>Using a survey gem that adds extra fields. I added a class called "jSlider" to the question and does display the slider, but does not update the input.</p> <p>html form generated:</p> <pre><code>&lt;fieldset class="q_default jSlider" id="q_353" name="17) On a scale of 0 to 10, ..."&gt; &lt;legend&gt;&lt;span&gt;17) On a scale of 0 to 10, ...&lt;/span&gt;&lt;/legend&gt; &lt;ol&gt;&lt;span class='help'&gt;&lt;/span&gt; &lt;input id="r_18_question_id" name="r[18][question_id]" type="hidden" value="353" /&gt; &lt;input class="" id="r_18_answer_id" name="r[18][answer_id]" type="hidden" value="3840" /&gt; &lt;li class="string optional" id="r_18_string_value_input"&gt;&lt;input id="r_18_string_value" maxlength="255" name="r[18][string_value]" type="text" /&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/fieldset&gt; </code></pre> <p>My js is:</p> <pre><code>$(".jSlider").each(function(){ var newSlider = '&lt;div style="margin-top:20px;margin-bottom:20px;" id="slider"&gt;0&lt;/div&gt;&lt;br /&gt;'; $(this).append(newSlider); $("#slider", this).slider({ value:0, min: 0, max: 10, step: 1, slide: function( event, ui ) { alert(ui.value); // when append, it adds to the fieldset // first parent is the fieldset, next should be the ol, then the li // finally arriving at the input field $(this).parent().next("ol").next("li").next("input:text").val(ui.value); } }); }); </code></pre> <h2>EDIT</h2> <p>Proposed edit to fix duplicate id breaks again.</p> <pre><code>$(".jSlider").each(function(){ var id = $(this).attr("id"); var sliderID = id + "_slider"; alert(sliderID); var newSlider = '&lt;div id="' + sliderID + '"&gt;&lt;/div&gt;&lt;br /&gt;'; $(this).append(newSlider); // or even // $(sliderID).slider({ $(sliderID, this).slider({ value:0, min: 0, max: 10, step: 1, change: function( event, ui ) { // alert(ui.value); // when append, it adds to the fieldset // first parent is the fieldset, next should be the ol, then the li // finally arriving at the input field $(this).closest('fieldset').find('input:text').val(ui.value); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload