Can I submit a html Like this: with
?
The method you can use to submit a specific form is the following:
// Grab the form element and manually trigger the 'submit' method on it:
document.getElementById("myForm").submit();
So in your example, you can add a click event handler on any element you like and trigger the form's submit method through that:
<form method="post" id="myForm">
<textarea name="reply">text</textarea>
</form>
<div class="submit">Submit the form by clicking this</div>
const myForm = document.getElementById("myForm");
document.querySelector(".submit").addEventListener("click", function(){
myForm.submit();
});
And if you want to do it jQuery style (which I do not recommend for such a simple task);
$("#myForm").submit();
In its full form:
const myForm = $("#myForm");
$(".submit").click(function(){
myForm.submit();
});
References:
JavaScript API
)jQuery
submit() API<?php
if(isset($_POST['text']) && !empty($_POST['text']))
{
echo $text_val = $_POST['text'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="Enter your action">
<p><label>Enter your Text : </label>
<input type="text" name="text" id="text" onmouseover="this.form.submit();"></input>
</p>
</form>
</body>
</html>
Using jquery:
$('#myForm').submit();
Yes, it's fairly simple. Just use the submit[jQuery docs] method inside of a click
handler function.
$("#myDiv").click(function() {
$("#myForm").submit();
});
If you prefer, you can do it with vanilla Javascript:
document.getElementById("myDiv").onclick = function() {
document.getElementById("myForm").submit();
};
How about this:
$(document).ready(function() {
$('#submitDiv').click(function() {
$('#myForm').submit();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="" id="myForm">
<textarea name="reply">text</textarea>
</form>
<div id="submitDiv">Submit the form by clicking this</div>
If you want to unnecessarily depend on JavaScript, then you could…
jQuery('div').click(function () { jQuery('form').submit(); });
… however, you should use semantic HTML that works without JS being present. So use a real submit button and apply CSS to make it look the way you want.