[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to show multiple options in dropdown and not one option

Posted on 2015-01-11
2
Medium Priority
?
81 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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

650 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