Jump to content

Ioan

Members
  • Posts

    5
  • Joined

  • Last visited

Ioan's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Ill try to do what Hadien said. It's a bit out of my level to understand but looks simple. This is the page I have so far. I want to be able to select items to make the edit and delete functions. There are also buttons to sort by name, id, rating etc. Then there is a save and load button that sends the arr_items to localStorage so it doesn't dissapear ever time the page is refreshed (those already work).
  2. it's an array filled with objects. When the user presses a button it creates a new object at the end of the array. What's in the object comes from what is currently in the text box <input type="button" class="bt" id="add" onmousedown="add()" value="Add" /> var arr_items = new Array;function obj_item(N) //the object has more than just Name in it but i simplified it here{ this.Name = N;}function add(){ arr_items[arr_items.length] = new obj_item(document.getElementById("inName").value);//comes from a text box in html showAll();//display everything in arr_items in a clickable text box}
  3. What is the best simple way to get javascript to tell html what value to pass to a function on click? The elements that hold the click event are created through javascript so I can't simply type in the parameters The actual goal is to have an "add" button in html that adds a new object with user defines attributes. The objects are automatically stored in an array so I can use loops. Then all the objects are displayed in some type of text field. The user should be able to click on each item in the text field which fills editable text boxes with that object's attributes. Everything seems to work, except the part when the user clicks on an object to display its attributes in javascript: function selected(i){ //this works if I hardcode a number instead of using i document.getElementById("inName").value = arr_items[i].Name;//puts a name into the value of a textbox with id "inName"}function showAll(){ var i; var outputName = ""; var l = arr_items.length;//the length of the array that holds objects var size = 0; for(i = 0; i < l; i++)//loop through all the items in the array { outputName += "<option id="+i+" onClick="+selected(i)+">"+arr_items[i].Name+"</option>";//tell html to create a new option tag, which should call a function with parameter i on click } document.getElementById("outName").innerHTML = outputName;//converts the string outputName to HTML code} in HTML: <select id="outName" class="out" size="20"></select> i'm new to this so maybe there are some useful keywords or tags that I don't know?
×
×
  • Create New...