Note that there are some explanatory texts on larger screens.

plurals
  1. POCall javascript function form jquery
    primarykey
    data
    text
    <p>I've got a problem with using javascript function inside Jquery. I want to get max and min value to the jquery SLIDER. Please help.</p> <p>Here is the markup.</p> <pre><code>$(document).ready(function() { </code></pre> <p>Here is the function MAX</p> <pre><code> function getMax() { var options = document.getElementById('.price_range').childNodes; var min = 999999999; for(var i = 0; i &lt; options.length; i++) { if(options[i].value &gt; max) max = options[i].value; } return max; } </code></pre> <p>Here is the function MIN</p> <pre><code>function getMin() { var options =document.getElementById('my_max').childNodes; var min = 999999999; for(var i = 0; i &lt; options.length; i++) { if(options[i].value &lt; min) min = options[i].value; } return min; } </code></pre> <p>Here comes the slider function, it has to get min and max values from javascript functions </p> <pre><code> // Slider $('#slider').slider({ range: true, min: getMin(), max: getMax(), step: 10, // Use this determine the amount of each interval values: [ 20, 40 ], // The default range slide: function( event, ui ) { $( "#amount" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] ); // for input text box $( "#my_min" ).val(ui.values[ 0 ]); // Display and selected the min Price $( "#my_max" ).val(ui.values[ 1 ]); // Display and selected the max Price } }); //For dropdown box $( "#my_min" ).val($( "#slider" ).slider( "values", 0 )); $( "#my_max" ).val($( "#slider" ).slider( "values", 1 )); $("select.price_range").change(function () { $myMinValue = $("#my_min option:selected").val(); $myMaxValue = $("#my_max option:selected").val(); //Make changes on the slider itself if($myMinValue &lt;= $myMaxValue) { $( "#slider" ).slider({ values: [$myMinValue, $myMaxValue] }); } else { alert("Invalid Input"); } }); }); </code></pre> <p>and here is the index.html</p> <pre><code> &lt;body&gt; &lt;select id="my_min" class="price_range"&gt; &lt;option value="0"&gt;0&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="20"&gt;20&lt;/option&gt; &lt;option value="30"&gt;30&lt;/option&gt; &lt;option value="40"&gt;40&lt;/option&gt; &lt;/select&gt; &lt;select id="my_max" class="price_range"&gt; &lt;option value="0"&gt;0&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="20"&gt;20&lt;/option&gt; &lt;option value="30"&gt;30&lt;/option&gt; &lt;option value="40"&gt;40&lt;/option&gt; &lt;/select &gt;&lt;!-- Slider --&gt; &lt;h2 class="demoHeaders"&gt;Slider&lt;/h2&gt; &lt;label for="amount"&gt;Price range:&lt;/label&gt; &lt;input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;"&gt; </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.
    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