Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts

    Using text link to do something

    I'm just learning PHP and after using actionscript a lot, I noticed they were very similar. The problem I'm having, though, is that with PHP you can't simply turn anything into a button and give it an onRelease code. What I want to do is have a text link that changes a variable when it is clicked.
    PHP Code:
    <?php $variable 7;
      echo 
    "<a href=\"thispage.php\" $variable = 6>Change Variable</a>"?>

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    PHP is a server side language... it can't control what happens on the users end. It processes information given and feeds back text to the user. To do what you want, you need a client side language (like actionscript), likely in this case, Javascript. It won't change any php variables directly, but there are ways to make it do what you want based on what it is you want to do.

    Wanna tell us a bit more of the goal?

  • #3
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    In actionscript you can do something like:
    myVariable = 7;
    on(release){
    myVariable = 8;
    }

    I want to basically do the same thing, except with a text link instead of a submit button.
    PHP Code:
    <?php $myVariable $_POST['varChange'];
        echo 
    $myVariable."<form action=\"this.php\" method=\"post\">
            <input type=\"text\" name=\"varChange\" />
            <input type=\"submit\" name=\"Submit\">
            </form>"
    ?>>
    Kind of a sloppy example, but I'm sure I could work with it to make it more like the actionscript example, but anyway, the submit button is the only way I know of to have a button do a PHP task. Instead of a button, I'd like to be able to use a text link.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Heh, so I wrote a big long piece of code when I reread your post/request.

    Basically, if you want to change a variable live on the page without going to another page, you'll need Javascript. Again, PHP is server side, it can't do anything locally. If you don't mind changing pages, you need to submit a form, basically what you did there. You can use a submit input or a button, but it has to be through a form. You can use CSS to make the submit button LOOK like a link (though it'll still be a button). If you want to use a link specifically, an anchor tag, you'll again need to use javascript.

  • #5
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    Okay, I guess I'll have to try it with javascript, then. I learned a little javascript back in 9th grade, I'll just pick up where I left off and put it on my list of languages to learn (I'll squeeze it in between PHP and C++).

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    As a suggestion (from someone who only seriously picked this up a few short years ago), focus on HTML and PHP first. Those are the backbones of webdesign, and I (and a number of other developers) believe that JS should augment a website, it should help a website out, but as users can (and often do) disable JS, your website should be able to work without it, unless its fulfilling a core element (google maps for example).

  • #7
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    Ya, that's why I've been trying to stay away from javascript (that and a lot of other reasons). I know HTML very well, I've been using it since 8th grade (3 or 4ish years ago). I've been using basic PHP a lot over the last year, mainly just includes and modifying pre-designed scripts, I actually just started went through the tizag tutorial yesterday, but I've got a pretty good idea how to use PHP, since it has a lot of similarities to actionscript, which I've been using since 9th grade, although PHP is a little more complex.


  •  

    Posting Permissions

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