简体   繁体   中英

Auto send html form after onclick return of php file

I am trying to write a website in which a form (that is supposed to be auto submitted) is the result of an onclick event displayed in an iframe. But hear me out. The core document has the html like this:

<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Welcome!</title>
        <link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="main.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="bootstrap/dist/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="script.js"></script>
    </head>
    <body>
     <iframe name="firstframe" id="firstframe">
      <p>Your browser does not support iframes.</p>
     </iframe><br>
    </body>
</html>

Into the iframe I load a php file with a JavaScript onclick event that is not much more but an empty form:

<form name="retrievedetails" id="retrievedetails" action="personalprocessor.php" method="get" >
</form onload="formAutoSubmit ()">

I would like to send this form as soon as that file was loaded into the iframe and get (in my case profile)info from a db as a return, hence the </form onload="formAutoSubmit ()">

The function formAutoSubmit() I have tried to give all possible variations but none work. They all look(ed) somewhat like this:

function formAutoSubmit () {
  document.forms["retrievedetails"].submit();
}

Everything works as intended if I give the get-form a submit button and press it myself but thats not what I intend. I have the feeling it has to do with the iframe not being able to load a JS script as it has no head, only the core document has the html-tag, head, body, etc.. But even giving the php-file that contains the get-form a head, body, etc. does not solve it.

I am sure the solution is obvious but I just do not see it. Could you give me pointer?

PS: If not obvious by now, I am not a learned programmer and write this site in my free time "for fun". If the entire approach seems odd to you, now you know why. I am very happy to hear an alternative solution as well but need a solution to the problem above.

Problem was, that onload cannot be called on a <form> element. It works fine on <body> , like numerous documentation on the internet already states. Thank you Chriss for giving comment that lead me there.

Sometimes the solution is right before your eyes and you just dont see it.

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