添加第二个文本框后,表单会自动停止提交吗?

时间:2014-08-26 02:18:17

标签: javascript html laravel

好的,所以我遇到了一个问题,如果我在表单中添加第二个文本框,它将不会自动提交任何理由,为什么?

<div id="myModal_play" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close icon-remove" data-dismiss="modal" aria-hidden="true"></button>
        <h3 id="myModalLabel">Start Game</h3>
    </div>
    <div class="modal-body">
        <p>Are you sure you want to put the game <span id="modal-game-play-name"></span> (Serial Num: <span id="modal-game-play-serial"></span>) into play?</p>
        <p>Please scan the box to put the game into play</p>
        {{ Form::open(array('route' => 'game.verifygame_post', 'class'=> 'form-horizontal')) }}
        <div class="control-group ">
            {{ Form::label('cash', 'Starting Cash Amount:', array('class' => 'control-label')) }}
            <div class="controls">
                <div class="input-append">{{ Form::text('cash', null, array('autofocus' => 'autofocus', 'placeholder' => 'Amount in till')) }}</div>
            </div>
            <br>
            {{ Form::label('barcode', 'Click and scan barcode', array('class' => 'control-label')) }}
            <div class="controls">
                <div class="input-append">{{ Form::text('barcode', null, array('autofocus' => 'autofocus')) }}</div>
                <div class="input-append"><input id="hidden_serial" name="hidden_serial" type="hidden"/></div>
            </div>
        </div>
        {{ Form::close() }}
        <p>This action cannot be undone.</p>
    </div>
</div>

以上是这样的:

的javascript:

function put_into_play(game_name, serial) {
   $('#modal-game-play-name').html(game_name);
   $('#modal-game-play-serial').html(serial);
    document.getElementById('hidden_serial').value = serial;
}

如果我删除第一个文本框“Starting Cash Amount:”并扫描文本框,它将正常工作。

但是,如果我将第一个文本框添加到此,则在扫描发生后它将无法提交? 关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

想出来。

我相信这是解决问题的方法。 我像这样添加了一个keyup调用:

   $('#modal-game-play-name').html(game_name);
   $('#modal-game-play-serial').html(serial);
    document.getElementById('hidden_serial').value = serial;
    $('#barcode').keyup(function(){
        if (this.value.length == 20){
            $('#verify_game_form').submit();
        }
    });

这将比等待20个字符一旦输入它将自动提交表格。