Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2012, 11:13 AM   PM User | #1
Hygeia
New to the CF scene

 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hygeia is an unknown quantity at this point
Question Need to get data from an array and display it as a new array

This is my HTML so far, i'm not really sure what to do =/ What I am trying to do is to present data that has been populated from checking a checkbox. The new array was populated by using the last function. I then want to be able to present the new array using javascript inside of the html file.



What I need is some code to put into my html file to make use of the last function (add items) I need it to print the new array onto the screen.

This is the html i used to print the first array onto the screen, though it doesn't seem to work for the new one.

<script type="text/javascript">
for(x=0; x<=computer.length-1; x++) {

document.write("<tr id='"+x+"'><td><label><input type='checkbox'name='item' value='"+x+"'/> "+computer[x].split(",")[0]+"</label></td><td>"+computer[x].split(",")[1]+"</td><td> <input name='qty' id='qty' type='textbox' value='0' onchange='qtychange(document.myform.qty);'/> </td><td>"+computer[x].split(",")[2]+"</td></tr>");

}
</script>

Here is all my Javascript

var computer = new Array();
var selected = new Array();
computer[0] = "10001, Nvidia Geforce GTX 690, $1200";
computer[1] = "10002, Raedon HD 7950, $450";
computer[2] = "20001, Ivy Bridge i7 3770, $400";
computer[3] = "20002, Ivy Bridge i7 3770k, $420";
computer[4] = "20003, Sandy Bridge i7 2700k, $340";
computer[5] = "20004, Bulldozer FX-8150, $270";
computer[6] = "30001, Antec eleven-hundred, $120";
computer[7] = "30002, Coolermaster HAF-X, $170";
computer[8] = "30003, Antec three-hundred, $50";
computer[9] = "30004, Corsair 550D, $160";
computer[10] = "40001, INTEL-ASrock fatal1ty Z77 Professional Motherboard, $250";
computer[11] = "40002, INTEL-ASrock Z77 extreme9 Motherboard, $350";
computer[12] = "40003, AMD-ASrock fatal1ty 990FX Professional Motherboard, $240";
computer[13] = "40004, AMD-ASUS Sabertooth 990FX Motherboard, $260";

function check(field) {
for (i = 0; i <= field.length - 1; i++) {
field[i].checked = true;
}
}

function uncheck(field) {
for (i = 0; i <= field.length - 1; i++) {
field[i].checked = false;
}
}

function addItems(field) {
for (i = 0; i <= field.length - 1; i++) {
if (field[i].checked == true) {
if (computer[i] != null) {
selected.push(computer[i]);
}
}
}
}
Hygeia is offline   Reply With Quote
Old 07-17-2012, 11:19 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

You should use DOM methods to display the new array.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-17-2012, 11:21 AM   PM User | #3
Hygeia
New to the CF scene

 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hygeia is an unknown quantity at this point
how? any suggestions on where to look? w3 schools is useless to me.
Hygeia is offline   Reply With Quote
Old 07-17-2012, 11:47 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Hygeia View Post
how? any suggestions on where to look? w3 schools is useless to me.
http://www.tizag.com/javascriptT/jav...innerHTML.php/

http://javascript.about.com/library/bldom06.htm
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 07-17-2012 at 11:50 AM..
Philip M is offline   Reply With Quote
Old 07-17-2012, 12:36 PM   PM User | #5
Hygeia
New to the CF scene

 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hygeia is an unknown quantity at this point
well i'm trying to get a new array to be presented though it is made up using parts of the original array. How do i "id" the array or elements =/

No i do not want to change data, and no i do not want to get rid of the array I already have on the screen

I want to get things from one side to the other, like a shopping cart

Last edited by Hygeia; 07-17-2012 at 12:39 PM..
Hygeia is offline   Reply With Quote
Reply

Bookmarks

Tags
array, form, html, javascript, shopping cart

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:06 AM.


Advertisement
Log in to turn off these ads.