1

i'm working on a little slider which provides a value that i want to use in php.. Now i've got the slider working it's storing its value in (var singleValues) but now i don't know how to send it correctly to php.

the slider:

function displayVals() {

        $( "#slider" ).slider();

        var step = $( "#slider" ).slider( "option", "step" );

        $( "#slider" ).slider( "option", "step", 20 );  

        var singleValues = $('#slider').slider('value');
        $("p.value1").html(singleValues); 

        $( "#slider" ).slider({
            change: function(event, ui) {displayVals();}
        });

    };

I have used xmlhttp before like down here V, but i don't know how to alter it to send (var singleValues) to a file.php

function achterpaneel(str)
    {
    if (str=="")
      {
      document.getElementById("rightColumn_content").innerHTML="";
      return;
      } 
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("rightColumn_content").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getAchterpaneel.php?r="+str,true);
    xmlhttp.send();
    }

Probably it's quite simple but I can't figure it out. stil have to learn a lot:)

Thanx!!

3 Answers 3

1

Since this line

xmlhttp.open("GET","getAchterpaneel.php?r="+str,true);

is sending a GET request and concatinates str to the request string, my guess would be to transform singleValues (which is JSON, I assume) to a query string and give this query string to the function call of achterpaneel - depending where you have to/want to call this method.

But: Ever heard of jQuery?

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for the mention of jQuery. I do NOT know why anyone is doing ajax any other way anymore. jQuery's ajax functions are much less code and much more flexible and compatible among browsers.
so im doing stupidly much ajax on a jQuery slider, if i try it the way i sugested :P but is there an easy jQuery way to send the singleValues to php?
0

i guess you use jQuery you can just use

$.get('url.php',{slider:$('#slider').slider('value')})

1 Comment

So this sends the value to 'url.php' ?? and in php i could use something like: $ValueSlider1=$_GET["value"]; ?? thanx for the help!
0

Call the press! :P

Got it working.. used the xmlhttp to set (r as "singleValues") which i then put in a variable in the php file like this ==> $r=$_GET["r"];

So this is what it turned out to be. If anyone has a better solution let me know :) This woks fine for me :D

 function slider2() {

        $( "#slider2" ).slider();

        var step = $( "#slider2" ).slider( "option", "step" );

        $( "#slider2" ).slider( "option", "step", 20 ); 

        var singleValues = $('#slider2').slider('value');
        $("p.value2").html(singleValues); 

        $( "#slider2" ).slider({
            change: function(event, ui) {slider2(); ValueToPhp();}
        });

                        if (singleValues=="")
                      {
                      document.getElementById("rightColumn_content").innerHTML="";
                      return;
                      } 
                    if (window.XMLHttpRequest)
                      {// code for IE7+, Firefox, Chrome, Opera, Safari
                      xmlhttp=new XMLHttpRequest();
                      }
                    else
                      {// code for IE6, IE5
                      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                      }
                    xmlhttp.onreadystatechange=function()
                      {
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
                        document.getElementById("rightColumn_content").innerHTML=xmlhttp.responseText;
                        }
                      }
                    xmlhttp.open("GET","ValueTest.php?r="+singleValues,true);
                    xmlhttp.send();


    };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.