用于检查是否单击div的php代码

Can anyone help me .I need php code for checking whether a div is clicked or not.

like,

if (isset($_POST['Submit1'])) { }

But instead of submit button i need a div ... anyone help me please

thanks

You will need JavaScript for this as PHP doesn't access the DOM if I'm reading your question correctly. I would recommend you add jQuery lib to your page as it's simpler to add click event to a DIV, otherwise you have to add an event listener in javascript yourself for click events on the DIV.

jQuery: http://api.jquery.com/click/

DIY: http://www.codingforums.com/archive/index.php/t-122993.html

PHP can't tell you if a div has been clicked as php only works on the Server. For this you need javascript.

jquery makes something like this very simple.

Can't quite imagine what can be this test good for, but you can use javascript like this:

<div id="clickable_div" onclick="document.getElementById('divclicked').value='YES'"> SOMETHING </div>

in your form

<input type="hidden" id="divclicked" name="divclicked" value="NO"/>

and in php

if ($_POST['divclicked']=='YES') {...} else {...}

I can't tell if you want a div to be treated as a form element, like a checkbox, or if you want to use a div to submit a form.

Using it as a form element has been explained by Stano, if you want the div to submit a form, you really should just use a submit button. If you want to use an image instead of a button, using <input type="image"...> will function as a submit button.

If you really need to use a div to submit the form, you will need javascript. Something like this, we take a form named "bald" and when you click the div, the form "bald" is submitted as if you pressed a submit button.

<form name="bald" action="somefile.php">
    <div onclick="bald.submit();">Click here to submit</div>
</form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​