...

View Full Version : Using text link to do something



djh101
06-25-2010, 01:49 AM
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 $variable = 7;
echo "<a href=\"thispage.php\" $variable = 6>Change Variable</a>"; ?>

Keleth
06-25-2010, 02:06 AM
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?

djh101
06-25-2010, 02:26 AM
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 $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.

Keleth
06-25-2010, 03:05 AM
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.

djh101
06-25-2010, 03:24 AM
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++).

Keleth
06-25-2010, 03:32 AM
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).

djh101
06-25-2010, 03:52 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum