当文本框的内容发生变化时,自动提交表单

时间:2017-04-26 11:06:58

标签: javascript php jquery

我正在开发面部识别系统。当我用我的网络摄像头捕获图像时,网址被加载到表单中的文本框中。现在我希望表单提交并处理php,如果它是submnitted。这是我的表格

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" enctype="multipart/form-data" id="frmsubmit">
                                                <input type="text" class="form-control input-sm" id="imgsrc" name="imgsrc">
                                                    <input type="submit" value="AUTHENTICATE" class="btn btn-primary" data-loading-text="Loading..." name="send" id="submit">
                                                    </form>

和我的JAVASCRIPT

<script language="JavaScript">
webcam.set_api_url( 'present.php' );
    webcam.set_quality( 100 ); // JPEG quality (1 - 100)
    webcam.set_shutter_sound( true ); // play shutter click sound
    webcam.set_hook( 'onComplete', 'my_completion_handler' );

    function take_snapshot(){
        // take snapshot and upload to server
        document.getElementById('upload_results').innerHTML = '<h1>Uploading Image To Database...</h1>';
        webcam.snap();
    }

    function my_completion_handler(msg) {
        document.getElementById("imgsrc").value=msg;
        // extract URL out of PHP output
        if (msg.match(/(http\:\/\/\S+)/)) {
            // show JPEG image in page

            document.getElementById('upload_results').innerHTML ="<div class='alert alert-success fade in'> <i class='icon-remove close' data-dismiss='alert'></i> <strong>Success!</strong>Image Captured And Uploaded Successfully </div>";
            document.getElementById('upload_img').innerHTML ="<img src="+msg+" class=\"images\">";
            // reset camera for another shot
            webcam.reset();
            document.getElementById('frmsubmit').submit();
        }
        else {alert("PHP Error: " + msg);
    }
    }
</script>

和PHP代码

if(isset ($_POST["send"]))

{

4 个答案:

答案 0 :(得分:0)

如果你给表单一个id

WHILE index IS LESS THAN attendances.Count DO NOTHING

您可以使用jQuery

触发- INFOS: Exception when handling error trying to reset the response. javax.persistence.NoResultException: No entity found for query at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:498) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl java:43) at java.lang.reflect.Method.invoke(Method.java:498) 事件
<h:form prependId="false"> 
   <h:dataTable id="accounts_list"  class="table table-bordered table-striped table-hover table-condensed" 
   var="account" value="#{AccountBean.accountProvider.allAccounts}">
      <h:column>
         <f:facet name="header">
            <h:outputText value="account type"/>
         </f:facet>
         <h:outputText value="#{account.categoy.label}"/>
      </h:column>
      <h:column>
         <f:facet name="header">
            <h:outputText value="account code"/>
         </f:facet>
         <h:outputText  value="#{account.code}"/>
      </h:column>
      <h:column>
         <f:facet name="header">
            <h:outputText value=" department"/>
         </f:facet>
         <h:outputText  value="#{AccountBean.searchDepByAccountCode(account.code)}"/>
      </h:column>
                         .....
   </h:dataTable>
</h:form>

<form action="someaction" method="post" id="someform">

答案 1 :(得分:0)

使用提交按钮单击触发器例如

document.getElementById("submit").click();

您正在使用document.getElementById('frmsubmit')。submit();但是你没有任何带有这个id的表单,但你有提交id的提交按钮。所以这段代码对你有用。

答案 2 :(得分:0)

试试这个......

$('#imgsrc').on('change', function(){
   $(this).parent().submit();
})

答案 3 :(得分:0)

您可以将onchange属性添加到文本框

onchange="this.form.submit()"