BY Michael Singh, Stephen Sing, Deepika Pathinga
Q:
Write a short Javascript function which takes an id of a div tag as argument and adds a select dropdown to the inner html of this tag with 101 items: Select a Page, 00.html, 01.html, 02.html, 03.html... such that when an item other than the Select a Page is chosen the browser goes to that page.
A:
function addSelect(div) {
var select = document.createElement('select');
var selectHTML = "";
selectHTML="";
selectHTML += '<option selected value="">Pick a Page</option>';
var i;
for(i = 0; i < 101; i++) {
var j ="";
if(i < 10){
j="0";
}
selectHTML += '<option value="' +j+i+'.html' + '">' + j+i + ".html</option>";
}
selectHTML += "";
select.innerHTML = selectHTML;
select.onchange = function() {document.location.href=this.value;};
document.getElementById(div).appendChild(select);
}
Tested and it works.
(
Edited: 2016-05-16)
BY Michael Singh, Stephen Sing, Deepika Pathinga
Q:
Write a short Javascript function which takes an id of a div tag as argument and adds a select dropdown to the inner html of this tag with 101 items: Select a Page, 00.html, 01.html, 02.html, 03.html... such that when an item other than the Select a Page is chosen the browser goes to that page.
A:
function addSelect(div) {
var select = document.createElement('select');
var selectHTML = "";
selectHTML="";
selectHTML += '<option selected value="">Pick a Page</option>';
var i;
for(i = 0; i < 101; i++) {
var j ="";
if(i < 10){
j="0";
}
selectHTML += '<option value="' +j+i+'.html' + '">' + j+i + ".html</option>";
}
selectHTML += "";
select.innerHTML = selectHTML;
select.onchange = function() {document.location.href=this.value;};
document.getElementById(div).appendChild(select);
}
Tested and it works.