?
Solved

How to show multiple options in dropdown and not one option

Posted on 2015-01-11
2
Medium Priority
?
80 Views
Last Modified: 2015-01-11
I have a select that is populating but I need it to list all number of days instead of the total of days. For example if its 3 days  I need the dropdown to have option 1 day, option 2 days , option 3 days and not just option 3 days

var selectedDate = new Date();
				$( "#checkout" ).datepicker({
					dateFormat: 'yy-mm-dd',
					defaultDate: "+1w",
					changeMonth: false,
					numberOfMonths: 1,
					showOn: 'button',
					buttonText: '<i class="calendar"></i>',					
					prevText: '<i class="chevron-left"></i>',
					nextText: '<i class="chevron-right"></i>',			
				});
				$("#checkout").datepicker("option", "minDate", selectedDate);


$('#checkout').datepicker().bind("change", function () {
    calculate();
});

function calculate() {
    var d1 = new Date();
    var d2 = $('#checkout').datepicker('getDate');
    var diff = 1;
    if (d1 && d2) {
        diff = diff + Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
		
	var QTY = [diff];    
    var sel = document.getElementById('duration');
for(var i = 0; i < QTY.length; i++) {
    var opt = document.createElement('option');
    opt.innerHTML = QTY[i];
    opt.value = QTY[i];
    sel.appendChild(opt);
}
    }
}

Open in new window

0
Comment
Question by:ucohockey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40543657
Try changing lines 26-33 to:
        var sel = document.getElementById('duration');
        sel.innerHTML = ""; // clear
        for(var i = 0; i < diff; i++) {
            var opt = document.createElement('option');
            opt.innerHTML = (i+1) + ' day' + (i>0?'s':''); // opt.text
            opt.value = i+1;
            sel.appendChild(opt);
        }

Open in new window

Note that the option value and text are different (on purpose). I made a jsFiddle, when you click submit you see the form values: http://jsfiddle.net/robert_schutt/heamy7LL/1/
0
 

Author Closing Comment

by:ucohockey
ID: 40543660
Works perfect thanks
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question