dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Pass Javascript results to PHP

  1. #1
    Join Date
    May 2009
    Posts
    1

    Exclamation Pass Javascript results to PHP

    Hi everybody! I'm new to this forum and full of hope to solve this issue.
    Please help out if you can!

    So, I have slider on page that goes from 0 to 100. and I need to pass the value that visitor selected to the next page by using submit button.

    Here is javascript code that I have for the slider.
    -----------------------------------------------
    <script type="text/javascript">
    window.addEvent('domready', function(){
    var slider1 = new Slider('slideContainer1', 'slideHandle1',{onComplete: function(val){$('pos1').setHTML(val);}});
    var slider2 = new Slider('slideContainer2', 'slideHandle2', {
    onTick: function(pos){
    this.knob.effect(this.p, {duration: 200, transition: Fx.Transitions.quadOut}).start(pos);
    },
    onComplete: function(val){
    $('pos2').setHTML(val);
    },
    steps: 5
    });
    });
    function SetJsValue()
    ----------------------------------------------
    Next page will catch value by $_post or $_get. I guess.

    Please if you have any ideas let me know.
    I'm new to javascript and would really appreciate your help.

  2. #2
    Join Date
    Mar 2007
    Location
    USA
    Posts
    449
    If you've got a form with submit button passing your variables to the next page with GET or SEND, the easiest way to pass the variable from js to php is just to have your script change the value of a hidden input in the form before it submits that way you can grab it on the next page.

    Or if your slider is an input element inside the form already you should be able to grab that as long as it's been named.

  3. #3
    Join Date
    May 2009
    Posts
    21
    Wht do you mean by next page? Are you talking the page from the server or the page at the client side?

    Server side use a manual GET, client side just pass the information into a cookie then collect from cookie at new page.

  4. #4
    Join Date
    Sep 2005
    Posts
    73
    Hi
    I tried many ways to pass variables,
    IT WILL NEVER WORK IN A ONE CODE
    JavaScript runs on the BROWSERS machine,
    PHP runs on the SERVER
    so it will NOT work!

    you CAN use PHP to build the J.S script using echo command,
    echo '<script> function XXX(); {
    do this'. $php_variable1.'
    do that'. $php_variable2.'
    }' ;
    but passing JavaScript Variables to PHP is possible
    ONLY using a FORM as written before.

    <form name="myform">
    <input type="hidden" name="field1">
    <script>myform.field1.value = "what ever variable or fixed value";</script>
    </form>

    OR
    <form.....>
    <input type="hidden" value="<?php echo $php_variable1 ;?>" name="field1">
    </form>

    GoodLuck!
    Last edited by Lazer; 05-20-2009 at 02:53 AM. Reason: forgot php variables

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles