简体   繁体   中英

JavaScript for comparing combo date with date picker date

I want to select the date in combo box which is less-than or equal to date selected in date picker. I am using this code. Note combo box contains the dates from database in an array.

But its not working as per my requirement.

function copytxt(){
        var w = document.getElementById("dateoil").value;
        document.getElementById("cb1").value <= w;}

If "dateoil" represents date picker and "cb1" represents combo box. Then from what I have understood, this might be helpful:

function copyText() {
        var dp = document.getElementById("dateoil").value;
        var cb = document.getElementById("cb1").value;
        if(cb <= dp) {
           cb = dp;
        }
   }

Assuming the combo box receives the data from database and its an array of positive decimal values. Then this could be one of the ways to achieve the desired output.

function setValue() {
        var dp = document.getElementById("dateoil");
        var cb = document.getElementById("cb1").value;
        var comboValues = [];
        for (var i = 0; i < dp.length; i++){ 
            if(dp[i].value <= cb){
              comboValues.push(parseFloat(dp[i].value));
            }
        }
        dp.value = comboValues.sort().pop();
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM