[英]Can I send a form using <h3> tag using js
I want to send a form without using button.我想在不使用按钮的情况下发送表单。 I want to send it when the user clicks on the text so can I do it using JS or not.
我想在用户单击文本时发送它,所以我是否可以使用 JS 来发送它。 this is my code
这是我的代码
function stateChanged() {
if (xmlHttp.readyState==4){
//document.updateForm.qty.value=xmlHttp.responseText;
var val = xmlHttp.responseText;
var res = val.split("#");
var html="<table>";
for(var i=0; i<res.length-1 ; i++ ){
//document.getElementById('results').innerHTML +="<tr><td> <a href='www.google.com'>" + res[i] + '</a></td></tr>';
// html+="<tr><td></form> <a href = "+ 'changeRoles.php?un=' + res[i] + '>'+ res[i] + "</td></tr>";
html+= "<tr><td><form name = 'choose' method='post'> <h3 onclick='document.choose.submit();'>"+res[i]+"</h3> <input type='hidden' name = 'un' value = '"+ res[i]+"'> </form></td></tr>";
}
html+="</table>";
document.getElementById('results').innerHTML =html;
}
}
Technically, yes, it is possible.从技术上讲,是的,这是可能的。 Just add the target url to the form element's
action
attribute.只需将目标 url 添加到表单元素的
action
属性中。
But why would you want to break user expectations and best practices for UI design?但是你为什么要打破用户对 UI 设计的期望和最佳实践呢?
<table> <thead/> <tbody> <tr> <td> <form action="<your url goes here>" name='choose' method='post'> <h3 onclick='document.choose.submit();'>Whatsup</h3> <input type='hidden' name = 'un' value = 'blarf'> </form> </td> </tr> </tbody> </table>
First define a callback method首先定义一个回调方法
call the defined method from <h3> tag从 <h3> 标签调用定义的方法
Example is given below.下面给出示例。
Try and let me know whether you have any further query尝试让我知道您是否有任何进一步的疑问
function action1()
{
$.ajax({
url : 'example.com',
type: 'GET',
success : handleData
});
}
<h3 onclick='action1();'>Submit</h3>
It will run.它会运行。 Just copy paste once.
只需复制粘贴一次。 Check it.
核实。 Then let me know if you have any other query.
如果您还有其他疑问,请告诉我。
function action1() { $.ajax({ url: 'some_unknown_page.html', success: function (response) { alert("I am success"); }, error: function (jqXHR, exception) { alert("I am clickable"); }, }); }
<html> <header> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </header> <body> <form name = 'choose' action="asdada" method='post'> <h3 onclick='action1();'>Click Me</h3> </form> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.