Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass jQuery variable using Ajax get request?
    text
    copied!<p>I have a values generated by a jQuery slider. I need to pass its variable to a url in the form <a href="http://domain.com/index.php?rich=3&amp;sweet=6" rel="nofollow">http://domain.com/index.php?rich=3&amp;sweet=6</a>. I need to use Ajax's get request to send the javascript variables (rich and sweet) to the url.</p> <p>I have the following javascript in my index.php file (the variables are assigned values set by the select/slider HTML code), selectToUISlider() couples the slider to a pulldown menu:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { $('#rich').selectToUISlider({ labels:7, sliderOptions: { stop: function(e,ui) { var richValue = $('#rich').val(); }}}).next(); $('#sweet').selectToUISlider({ labels:7, sliderOptions: { stop: function(e,ui) { var sweetValue = $('#sweet').val(); }}}).next(); } &lt;/script&gt; ........ </code></pre> <p>The HTML code below (I omitted the 'sweet' select code)</p> <pre><code> &lt;form action="index.php" name="form1" method="GET"&gt; &lt;!-- demo 1 --&gt; &lt;fieldset&gt; &lt;select name="rich" id="rich" onchange="this.form.submit()"&gt; &lt;optgroup label="Not too Rich"&gt; &lt;?php $rich1 .= '&lt;option'.(isset($_GET['rich']) &amp;&amp; $_GET['rich']=='1' ? ' selected ' : ' ').'value="1"&gt;'.'Not too Rich'.'&lt;/option&gt;'."\n"; ?&gt; &lt;?php echo $rich1 ?&gt; ......................... &lt;?php $rich7 .= '&lt;option'.(isset($_GET['rich']) &amp;&amp; $_GET['rich']=='7' ? ' selected ' : ' ').'value="7"&gt;'.'Super Rich'.'&lt;/option&gt;'."\n"; ?&gt; &lt;?php echo $rich7 ?&gt; &lt;/optgroup&gt; &lt;/select&gt; &lt;/fieldset&gt; </code></pre> <p>My understanding is that I have to work this:</p> <pre><code>$.get('index.php?rich='+ $('#rich').val() , function(data) { $('#rich').html(data); }); </code></pre> <p>into the code somehow but I don't know how.</p>
 

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