tomwaits4noman
02-28-2009, 05:53 PM
Hello I am looking to use javascript to bring a list of 7 items when I press a button on the page
the problem is that there are two lists so I need two buttons for each list.
e.g when press button A it brings up a list of nos 1 to 7
when you press button B it brings up a list of the days of the week
I was advised to use arrays and string queries, I made an attempt the code is provided below but I am not sure how to program the javascript to load the second list
thanks.
<script>
var myArr = new Array("1", "2", "3", "4", "5", "6", "7");
var urArr = new Array( Monday,Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
function drawList(the_array, l_type) {
the_type_open = "<" + l_type + ">";
the_type_close = "</" + l_type + ">";
/*30*/
the_string = the_type_open;
for(i=0;i<the_array.length;i++) {
the_string += "<li />" + the_array[i];
}
the_string += the_type_close;
document.getElementById("content").innerHTML = the_string;
// alert(the_string);
}
</head>
<body onLoad="drawList(myArr, 'ul');">
and in the body
I placed the following code
<div id="content">
<input type="text" id="name_textBox" value="Mary" /><button onClick="drawList();">Submit</button>
</div>
the problem is that there are two lists so I need two buttons for each list.
e.g when press button A it brings up a list of nos 1 to 7
when you press button B it brings up a list of the days of the week
I was advised to use arrays and string queries, I made an attempt the code is provided below but I am not sure how to program the javascript to load the second list
thanks.
<script>
var myArr = new Array("1", "2", "3", "4", "5", "6", "7");
var urArr = new Array( Monday,Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
function drawList(the_array, l_type) {
the_type_open = "<" + l_type + ">";
the_type_close = "</" + l_type + ">";
/*30*/
the_string = the_type_open;
for(i=0;i<the_array.length;i++) {
the_string += "<li />" + the_array[i];
}
the_string += the_type_close;
document.getElementById("content").innerHTML = the_string;
// alert(the_string);
}
</head>
<body onLoad="drawList(myArr, 'ul');">
and in the body
I placed the following code
<div id="content">
<input type="text" id="name_textBox" value="Mary" /><button onClick="drawList();">Submit</button>
</div>