Auto-Submit Form using JavaScript

前端 未结 5 463
你的背包
你的背包 2020-11-30 02:22

相关标签:
5条回答
  • 2020-11-30 02:25

    Try this,

    HtmlElement head = _windowManager.ActiveBrowser.Document.GetElementsByTagName("head")[0];
    HtmlElement scriptEl = _windowManager.ActiveBrowser.Document.CreateElement("script");
    IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
    element.text = "window.onload = function() { document.forms[0].submit(); }";
    head.AppendChild(scriptEl);
    strAdditionalHeader = "";
    _windowManager.ActiveBrowser.Document.InvokeScript("webBrowserControl");
    
    0 讨论(0)
  • 2020-11-30 02:42

    Try using document.getElementById("myForm") instead of document.myForm.

    <script>
    var auto_refresh = setInterval(function() { submitform(); }, 10000);
    
    function submitform()
    {
      alert('test');
      document.getElementById("myForm").submit();
    }
    </script>
    
    0 讨论(0)
  • 2020-11-30 02:43

    A simple solution for a delayed auto submit:

    <body onload="setTimeout(function() { document.frm1.submit() }, 5000)">
       <form action="https://www.google.com" name="frm1">
          <input type="hidden" name="q" value="Hello world" />
       </form>
    </body>
    
    0 讨论(0)
  • 2020-11-30 02:45

    You need to specify a frame, a target otherwise your script will vanish on first submit!

    Change document.myForm with document.forms["myForm"]:

    <form name="myForm" id="myForm" target="_myFrame" action="test.php" method="POST">
        <p>
            <input name="test" value="test" />
        </p>
        <p>
            <input type="submit" value="Submit" />
        </p>
    </form>
    
    <script type="text/javascript">
        window.onload=function(){
            var auto = setTimeout(function(){ autoRefresh(); }, 100);
    
            function submitform(){
              alert('test');
              document.forms["myForm"].submit();
            }
    
            function autoRefresh(){
               clearTimeout(auto);
               auto = setTimeout(function(){ submitform(); autoRefresh(); }, 10000);
            }
        }
    </script>
    
    0 讨论(0)
  • 2020-11-30 02:51

    This solution worked for me:

    <body onload="setTimeout(function() { document.myform.submit() }, 5000)">
       <form action=TripRecorder name="myform">
          <textarea id="result1"  name="res1" value="str1" cols="20" rows="1" ></textarea> <br> <br/>
          <textarea id="result2" name="res2" value="str2" cols="20" rows="1" ></textarea>
       </form>
    </body>
    
    0 讨论(0)
提交回复
热议问题