Jump to content

Select From Array


inktherapy

Recommended Posts

Hi.I managed to write a simple program that will store datas, select which data you want and display it.But what I want to do next is to display the datas that I did not select, separated from what I selected.e.g. My selected data: Van HalenThe datas that I did not select but I want to also view here: Mr. Big, Poison, Dream Theater, etc.I have my code here, please check hoping you could help me learn more thanks.

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>SelectFromArrays</title><script type="text/javascript">function storeEx() {var x = new Array();var y = 1;var z;var a;for (i=0; i<y; i++) {x[i] = prompt("Enter Data");z = confirm("Another data?");if (z == true) {y++;} else { a = parseInt(prompt("Enter Which Bank"));document.getElementById("display").innerHTML= x[a];}}}window.onload = storeEx;</script></head><body><div id="display"></div></body></html>

Link to comment
Share on other sites

Let's create another div that will display the rest of the data. You can of course display the data in any fashion you like.Second, the idea is to remove the selected index from the array, and only display the rest. You can do that with array.splice(theIndexToBeRemoved, 1). If the second argument is more than one, that many elements from the specified index on will be removed. See the W3Schools reference on array.splice() for more info.

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>SelectFromArrays</title><script type="text/javascript">function storeEx() {var x = new Array();var y = 1;var z;var a;for (i=0; i<y; i++) {x[i] = prompt("Enter Data");z = confirm("Another data?");if (z == true) {y++;} else { a = parseInt(prompt("Enter Which Bank"));document.getElementById("display").innerHTML += x[a];x.splice(a, 1);document.getElementById("whatWasAlsoEntered").innerHTML += x;}}}window.onload = storeEx;</script></head><body><div id="display">You selected: </div><div id="whatWasAlsoEntered">You also entered: </div></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...