简体   繁体   中英

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. 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.

But why would you want to break user expectations and best practices for UI design?

 <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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM