如何使用div作为输入? [关闭]

I want to click a div and use that as an input for php. So basically clicking a div will give a value to a variable in php. How ca I do that?

There are several ways to achieve this.

But all of them requires knowledge in javascript (JQuery for more advanced features).

You could try create a form with an hidden input and by clicking the div it will put the value in there and submit a form.

For example:

HTML:

<div id = "settingValue" data-value = "some value">Click Me</div>
<form id = "myForm" action = "myPhpFile.php" method = "post">
  <input type = "hidden" name = "myName" id = "gettingValue">
</form>

Javascript:

$('#settingValue').click(function(){
  var value = $(this).data('value');
  $('#gettingValue').val(value);
  $('#myForm').submit();
});

And in your myPhpFile.php

<?php
$value = $_POST['myName'];
?>