Changing a variable onclick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pmatos

    Changing a variable onclick

    Hi all,

    How can I in php have a link that reloads the exact same page but
    before reloading, changes some variables?

    Cheers,

    Paulo Matos

  • NC

    #2
    Re: Changing a variable onclick

    pmatos wrote:[color=blue]
    >
    > How can I in php have a link that reloads the exact
    > same page but before reloading, changes some variables?[/color]

    echo '<a href="', $_SERVER['PHP_SELF'],
    '?foo=1&bar=2"> Click here to change variables</a>';

    When the script reloads, you can access the values of
    foo and bar as $_GET['foo'] and $_GET['bar'], respectively.

    Or, you could just save them as session variables...

    Cheers,
    NC

    Comment

    • pmatos

      #3
      Re: Changing a variable onclick

      [color=blue]
      > echo '<a href="', $_SERVER['PHP_SELF'],
      > '?foo=1&bar=2"> Click here to change variables</a>';[/color]

      Ah, nice... Didn't know keywords sent in the URL would be sent as GET
      variables.
      :)

      Thanks,

      Paulo Matos

      Comment

      • Alvaro G Vicario

        #4
        Re: Changing a variable onclick

        *** pmatos wrote/escribió (1 Mar 2005 07:38:59 -0800):[color=blue]
        > How can I in php have a link that reloads the exact same page but
        > before reloading, changes some variables?[/color]

        Code to generate a link:

        <a href="<?=$_SERV ER['PHP_SELF']?>">Self page</a>


        Code to change a variable:

        $foo=33;



        --
        -- Álvaro G. Vicario - Burgos, Spain
        -- Thank you for not e-mailing me your questions
        --

        Comment

        • NC

          #5
          Re: Changing a variable onclick

          pmatos wrote:[color=blue]
          >
          > Ah, nice... Didn't know keywords sent in the URL would be sent
          > as GET variables.
          > :)[/color]

          Of course. That's how the GET method works...

          Cheers,
          NC

          Comment

          • Chung Leong

            #6
            Re: Changing a variable onclick


            "pmatos" <pocm@sat.ine sc-id.pt> wrote in message
            news:1109691539 .495324.43280@z 14g2000cwz.goog legroups.com...[color=blue]
            > Hi all,
            >
            > How can I in php have a link that reloads the exact same page but
            > before reloading, changes some variables?
            >
            > Cheers,
            >
            > Paulo Matos
            >[/color]

            Link to a PHP file that sets the variable, then do a header("HTTP/1.0 204 No
            Contents"), so the browser just stays at the current page.


            Comment

            Working...