SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Location
    UK
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP reaction to user clicks

    I'm a novice at programming, just started to dabble with PHP and a little JS.
    I imagine this is a fairly basic thing to do but have not found any info on it yet, I have looked.
    How to I get my PHP code to react to users clicking links on the page. For example if they click one link, it will set a variable to one value, if they click another it changes to a different value, or maybe execute a function.
    Or is this something I would be better off doing with JS?

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi
    If you want the action after user clicks to be done without refreshing /open page, you need to use Ajax (JavaScript).
    If you want that link to open s php file and send some value, define the link like this:
    file.php?name=value

    Then, in file.php get the value with: $val = $_GET['name'];

    - You can look on the net for: "php get post".
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Location
    UK
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tanks for the answer.
    I don't want to refresh, so I think I will go with Ajax.
    If I have a page with some embedded media, and I want to switch that media by clicking links on the page.
    At present I have something that works, but it's a messy workaround with an iframe targeted to other pages that contain just the embed code.
    I have just changed the site from HTML to PHP and wondered if there was a smarter more efficient way to do this.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can switch that media with JavaScript, changing the media file address in the "href" or "src" attribute of the html tag.
    Exemple:
    Code:
    document.getElementById('embed_tag_id').src = 'other_scr_address';
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  5. #5
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    370
    Mentioned
    6 Post(s)
    Tagged
    2 Thread(s)
    Check out Cjax framework, which allows you to write Ajax code with PHP only.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Location
    UK
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was about to say it would not be that simple, because of the nature of the embed code. The media is 360 panos from 360cities.net
    The code I got at the time I wrote the page was an object with loads of params that made it work in both IE and FF. That was the reason I needed the workaround with other pages containing the code.
    But going on 360cities today, the embed code they give you now is just an iframe with a src="URL", much simpler to work with I may not even need scripting to do it now, though I will look at your suggestions, I do need to learn more scripting.
    Last edited by Mittineague; Sep 19, 2013 at 10:55. Reason: removing unnecessary link


Bookmarks

Posting Permissions

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