当前位置: 动力学知识库 > 问答 > 编程问答 >

html - php code for checking whether a div is clicked or not

问题描述:

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.

网友答案:

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>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
网友答案:

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 {...}
分享给朋友:
您可能感兴趣的文章:
随机阅读: