Results 1 to 4 of 4

Thread: Javascript click detection with PHP action

  1. #1
    Join Date
    Jul 2013

    Question Javascript click detection with PHP action

    Hi, am kind of noob when it's comes to Javascript... and English also but i will try to do my best!

    I have this boxes in my admin menu, and this boxes can ether be closet or opened depending on if you click inside a div.
    And what i want is to someway detect this click and have a action with PHP code.

    I would love if someone could help med with this. Thanks in advance.

    HTML Code:
    <script type="text/javascript" src="style/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
    	$(".box .h_title").not(this).next("ul").hide("normal");
    	$(".box .h_title").not(this).next("#home").show("normal");
    	$(".box").children(".h_title").click( function() { $(this).next("ul").slideToggle(); });
    <div class="box">
    	<div class="h_title"> Main control</div>
    	<ul id="<?php echo ($active[0]); ?>">
    		<li class="b1"><a class="icon view_page" href="<?php echo (@$siteurl); ?>" rel='shadowbox'>Show your website</a></li>
    		<li class="b2"><a class="icon report" href="">Reports</a></li>
    		<li class="b1"><a class="icon add_page" href="">Add new page</a></li>
    		<li class="b2"><a class="icon config" href="">Site config</a></li>
    Also note that this Javascript code i have done whats forbidden when it's comes to programing (I have download it :O )
    that why i don't get a simple thing like this, as far as i know i should probably writ the PHP code somewhere in this line

    [ $(".box").children(".h_title").click( function() { $(this).next("ul").slideToggle(); }); ]

  2. #2
    Join Date
    Jul 2013
    I'm not sure I understand right – what PHP action do you want to trigger?

    Generally speaking, you might have some misconceptions here. PHP is a server-side language and will be executed before the website is even delivered to the client. Javascript, however, is a client-side language* whose code will be delivered to the client in raw form and executed on his computer. This means, for Javascript to trigger any PHP action in a dynamic way, there is no way around a new page request.
    This request could be done "in the background" without reloading the entire page by using Ajax calls – again, it just depends on what action you want to trigger. Maybe a full page reload is the way to go, maybe the action can even just be written in Javascript.

    *) There is server-side Javascript, nodejs, but this is something different.

  3. #3
    Join Date
    Jul 2013
    Okey, first of all thanks for replying.

    So what i want is to have a change in the database. So as you can see this <UL> tag has a PHP variable inside.

    HTML Code:
    <ul id="<?php echo ($active[0]); ?>">
    This is the PHP code hows making this variable ($active[0])

    PHP Code:

    $querybox "SELECT * FROM `admin-boxactive`";
    $resultbox mysql_query($querybox);

    $counter 0;

    $rowbox mysql_fetch_assoc($resultbox))
        if (
    $active$counter ] = "home";
    $active$counter ] = "";

    The active column can ether be EQL to 1 or 0 (ON or OFF) So when it's EQL to 1 the variable is EQL to Home, that's means the box is open.

    The PHP action i want to create is a code hows chancing this number in the database. So if i click my mouse on the <div> tag when its open (EQL to 1) then the number change to 0 witch is EQL to closed

  4. #4
    Join Date
    Jul 2013
    Then this is exactly what I was talking about in my previous post: You need another server-side action, which means that it cannot be done in Javascript alone. Assuming you don't want the user to leave/reload the page when clicking on such a box, you need a PHP file that updates this value in the database based on an argument that can f.ex. be sent via GET or POST (your choice – it depends on how sensitive these values are). Then, when the click is triggered, you send an Ajax request to this script.

    You should read up on these things, think about it, and give it a try and if it doesn't work out, show what you have tried.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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