0

Is it actually possible to set a php session variable with onblur() to the value on a textbox. Research tells me it shouldn't work but:

onblur="<?php $_SESSION["limit"] = "3" ?>" 

appears to. What I want to do is set a session variable so when a link is clicked, the variable takes the value of the textbox.

<form method="post" onblur="<?php $_SESSION["limit"] = (this.limitbox.value) ?>">
    <input type="text" name="limitbox" value="0" width="5" style="width:40px;"/ >
    recipients
</form>

I understand php is server side but don't know if there is a simple way to do this or to be honest, what way is best. I have checked previous posts but can't find an answer I understand so please don't mark me down if you find one that answers this and you understand it. This is closest: I'm trying to use a textbox value as a session variable

Community
  • 1
  • 1
sharon
  • 55
  • 7

1 Answers1

0

Using ajax to set session

    // set onblur
    onblur="doAjax(this)"


    // function doAjax to set session
    function doAjax(obj)
    {
      $.ajax({
        url:'file_to_set_session.php',
        dataType:'json',
        method:'get',
        data: {"limit": this.limitbox.value}
        success:function () {
          //do something
        }
      });
    }


    // file_to_set_session.php
    $_SESSION["limit"] = $_GET["limit"];
dilbadil
  • 316
  • 2
  • 7