Image one is how the page appears when loaded by the browser. Image 2 is when the list element is double clicked. Image 3 shows the result of clicking the pencil (which is the original form element). You can see that the list item does have an accessible value as it prints the integer in the alert so I am not sure about the comment below pertaining to that . I am also not understanding how this is a duplicate of the previous question suggested as when the img is clicked it satisfies the logic check of $_POST['edit']. Please do not mark this as duplicate as it is not! In the answer my question was marked as a duplicate of it is stated that "img input elements cannot post data to the server and must be encased in a button". This to my mind must be incorrect as how can my page change state based on the img click if it is not delivering data via post, how can the POST variable be set by the img click if it cannot pass data to the server. If a question is marked as duplicate then the original answer must address the same problem and/or contain correct information if it does not then I fell this question should stand as an original!
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<?php
if(isset($_POST['edit']) )
{
?>
<p>window is in edit mode</p>
<?php
}
else
{
?>
<p>window is not in any mode</p>
<form id="form-edit" method="POST" name="form-edit" action=" <?php echo $_SERVER['PHP_SELF']; ?>">
<input type="image" id="edit-button" name="edit" value="1" src="../images/pencil.png" class="course-banner-edit">
</form>
<?php
}
?>
<script>
$(document).ready(function() {
/**********************************************
PROBLEM WITH THIS FUNCTION
**********************************************/
$('li').dblclick(function() {
$('#form-edit').submit();
/******************************************
THE ALERT TRIGGERS AND THE VALUE IS REPORTED AS ONE WHICH IS CORRECT
*****************************************/
alert( $("input[name=edit]").val() );
});
});
</script>
</body>
</html>