简体   繁体   English

我想通过单击选择框中的月份来显示上个月的余额

[英]i want to display previous month balance amount by clicking a month in select box

when i select a month in selectbox ,automatically previous month balance should display in the below text box. 当我在selectbox中选择一个月份时,上一个月的余额会自动显示在下面的文本框中。 i have db table like this: 我有这样的数据库表:

month:  year    amount:   
January  2015    2000
February   2015   3000:
dec:        2015   4000
dec:        2014   5000

if i click jan 2015 in select box i want to get prev month amount 5000: 如果我在选择框中单击Jan 2015,我想获得上个月的金额5000:

 <?php 
    $usr = $this->session->userdata('usr');
    echo form_open('money_c/addprevmonth');
?>
        <table border="0" style="margin-left:20px">
        <tr>
            <td>Month:</td>
            <td>
                <select name="month" style="margin-left:6px;">
                <option value="January">January</option>
                <option value="February">February</option>
                <option value="March">March</option>
                <option value="April">April</option>
                <option value="May">May</option>
                <option value="June">June</option>
                <option value="July">July</option>
                <option value="August">August</option>
                <option value="September">September</option>
                <option value="November">November</option>
                <option value="December">December</option></select>
            </td>
        </tr>
     <tr>
         <td>Year:</td>
         <td>
              <select name="year" style="margin-left:7px;    margin-top: 26px;">
          <?php  for($i=1990;$i<3000;$i++) {
                        echo "<option>".$i."<option>" ;
                        }
                ?>
                  </select>
             </td>
        </tr> 
     <tr>
         <td>Previous Month Balance:</td>
         <td><input type="text" value".iwant to display here....." ></td>
     </tr>
        <tr>
            <td>Cash in hand:</td>
            <td><input type="text" class="text" ></td>
        </tr>
   </div>
 </table>
  <div class="p-container">
     <!--<label class="checkbox"><input type="checkbox" name="checkbox" checked><i> </i>I Agree to the terms of use</label>-->
  </div>
    <input type="submit"  value="Add" >
    <?php echo form_close();?>

I outlined the base idea in this fiddle 我在这个小提琴中概述了基本思想

Basically you need to get the current selected month and year every time. 基本上,您需要每次获取当前选定的月份和年份。 So do something on 所以做点什么

var arrayOfMonths = [];

$("select[name='month'] > option").each(function()
{
    // Adds the value of the option to the array
    arrayOfMonths.push($(this).val());
});

$('select').on('change', function() {  
    //get selected month
    var month = $( "select[name='month']").find(":selected").text();
    var positionOfMonthInArray = $.inArray(month, arrayOfMonths);
    var previousMonthIndex = positionOfMonthInArray-1;
    //get selected year
    var year = $( "select[name='year']").find(":selected").text();

    if(previousMonthIndex == -1){
        //if index of month is -1 selected the last month
         previousMonthIndex = arrayOfMonths.length - 1;
         year = year - 1;
    }


//Do what you want here...
        alert(arrayOfMonths[previousMonthIndex]);
        alert(year);    

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从选择框中选择月份名称和特定月份的日期 - select month name and days of that particular month from select box 单击上一个/下一个月时,阻止jQuery Datepicker刷新 - Stop jQuery Datepicker from refreshing when clicking previous/next month 我想为甘特图的Jquery Libary查看月份与月份之间的差异 - I want to Jquery Libary for gantt Chart view month to month difference 我想在jQuery的单独的文本框中显示日期为日期,月份和年份 - I want to display date as date, month and year in seperate text boxes in jquery jQuery 上个月跳转到随机月份而不是上个月 - jQuery previous month jumps to random month instead of previous month 根据第一个选择框显示产品数量 - Display the amount of the product based on the first select box 全日历显示上个月和下个月的条目如何隐藏它 - Fullcalender display previous and next month entry how to hide this jQuery ui datepicker仅选择当前和前一个月 - jquery ui datepicker select only current and previous month jQuery Datepicker - 在选择框中显示完整的月份名称 - jQuery Datepicker - Show full month names in select box 全日历。 如果我隐藏了月份视图并导航到上个月,我该如何将事件重新呈现到它们的理想位置 - fullcalendar. If I hide month view and navigate to previous month, how could I rerender events to their perfect place
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM