如何在不键入

时间:2017-11-28 03:11:12

标签: javascript php jquery forms

我只想在下拉按钮中选择房间和时间后显示消息。我选择所有这些,它将以如下形式出现:



$(document).ready(function(){ 
    $('#rooms, #time').bind('input', function() {        
        $('#time_room').val($('#rooms').val() + ' ' +
                            $('#time').val() );
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="rooms" id="rooms">
    <option value="" style="display: none;">SELECT</option>
    <option value="cas 104">cas 104</option>
    <option value="cas 105">cas 105</option>
</select>

<select name="time" id="time">
    <option value="" style="display: none;">SELECT</option>
    <option value="7:00 - 8:00 am">7:00 - 8:00 am</option>
    <option value="8:00 - 9:00 am">8:00 - 9:00 am</option>
</select>

<form action="" name="form">
    <input type="text" name="time_room" id="time_room">
</form>
<div id="feedback"></div>
&#13;
&#13;
&#13;

上面的代码在index.php中,然后当我把这段代码放在其中时:

$("#feedback").load("check.php").hide();
$("#time_room").on('input', function(){
    $.post("check.php", { time_room: form.time_room.value }, 
    function(result){
        $("#feedback").html(result).show();
    });
});

和check.php内部

<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "subject_loading_for_csit";
$con = mysqli_connect($host, $user, $password, $database) or die ("could not connect");
if (mysqli_connect_errno()) {
    echo "connection failed:".mysqli_connect_error();
    exit;
}


$rmt = $_POST['time_room'];

$query =  mysqli_query($con, "SELECT * FROM subject_scheduled where room_time = '$rmt' ");
$count = mysqli_num_rows($query);

if ($count == 0) {
    echo "OK";
}else if($count > 0){
    echo "Already taken";
}?>

此代码有效,但最终,除非我尝试插入或编辑表单,否则不会显示该消息。

这是我完成选择所有房间和时间的时间: This is when I Finish to select all the room and time:

当我输入表格时。 and when I type in the form

0 个答案:

没有答案
相关问题