基于输入框的内容查询而不提交

时间:2017-10-25 08:05:27

标签: javascript php mysql ajax

我有一个“结果”输入框,每次在两个输入框上发生onchange事件时,它会连接两个输入框。我想做的是根据“结果”输入框的值创建一个mysql查询,并在不单击按钮的情况下将结果显示在另一个输入框上。这可能吗?

我现在尝试这样做超过4个小时但仍然没有在查询部分完成任务并将其显示在输入框上

function getdatefinal() {
    var tt = document.getElementById('startfinal').value;
    var months = document.getElementById('termfinal').value;
    document.getElementById('term').value = months;

    var interest = document.getElementById('interest').value;
    var sampledata = interest + '-' + months;
    document.getElementById('sample').value = sampledata;

    var date = new Date($('#startfinal').val());
    day = date.getDate();
    var date = new Date(tt);
    var newdate = new Date(date);

    newdate.setDate(newdate.getDate() + (months * 30));

    var dd = day;
    var mm = newdate.getMonth() + 1;
    var y = newdate.getFullYear();

    if (dd > 28 && mm == 2) {
        dd = 28;
    } else if ((dd > 30 && mm == 4) || (dd > 30 && mm == 6) || (dd > 30 && mm == 9) || (dd > 30 && mm == 11)) {
        dd = 30;
    }


    var someFormattedDate = mm + '/' + dd + '/' + y;
    document.getElementById('endfinal').value = someFormattedDate;
}
<table  class="table table-condensed">
     <h5>Final</h5>
            <tr>
          <td><div class="row">
        <div class="col-xs-4"><input id ="termfinal" name ="termfinal" type="number" class="form-control input-sm" onchange="getdatefinal()"></div></div>
        </td>
        <td><div class="row">
        <div class="col-xs-8"><input id="frfinal" name="frfinal" type="text"  class="form-control input-sm" readonly  value=""></div></div>
        </td>
        <td><div class="row">
        <div class="col-xs-8"><input id="mafinal" name="mafinal" type="text"  class="form-control input-sm" readonly  value=""></div></div>
        </td>
         <td><div class="row">
        <div class="col-xs-8"><input id="fafinal" name="fafinal" type="text"  class="form-control input-sm" readonly  value=""></div></div>
        </td>
         <td><div class="row"> <div class="col-xs-10"><input id="startfinal" name="startfinal" type="date"  class="form-control input-sm"  value="" onchange="getdatefinal()"></div></div>
        </td>
        <td><div class="row">
        <div class="col-xs-10"><input id="endfinal" name="endfinal" type="text"  class="form-control input-sm" readonly  value=""></div></div>
    </td>
      </tr>

</table>

    <div class="form-group">

                                <label class="col-md-4 control-label" for="interest">Interest Rate (%)</label>
                                <div class="col-md-4">
                                   <!--  <div class="input-group"> -->
                                           <input id="interest" name="interest" type="number"  class="form-control input-sm"  value="" onchange="getdatefinal()">
             <!--                          <span class="input-group-btn">
        <button  id="interestsubmit" name="interestsubmit" class="btn btn-default">Go!</button>
      </span> -->

                         <!--     </div> -->
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-md-4 control-label" for="frate">Sample</label>
                                <div class="col-md-4">
                                    <input id="sample" name="sample" type="text"  class="form-control input-sm"  value="">
                                </div>
                            </div>

                             <div class="form-group">
                                <label class="col-md-4 control-label" for="frate">Factor Rate</label>
                                <div class="col-md-4">
                                    <input id="frate" name="frate" type="text"  class="form-control input-sm"  value="">
                                </div>
                            </div>

这是SQL数据库

CREATE TABLE mytable(
   Code        VARCHAR(6) NOT NULL PRIMARY KEY
  ,Factor_Rate NUMERIC(11,9) NOT NULL
);
INSERT INTO mytable(Code,Factor_Rate) VALUES ('1-1',1.01);
INSERT INTO mytable(Code,Factor_Rate) VALUES ('1-2',0.5075);
INSERT INTO mytable(Code,Factor_Rate) VALUES ('1-3',0.34);

0 个答案:

没有答案