• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Trying to create an array full of ongoing numbers with add/remove buttons, not showing up on page

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, here's my problem:

I have a div tag, and 2 buttons: Add and Remove.

The add button is supposed to add a number starting at one. The Remove button is supposed to remove a number from the array and output the updated array.

I have 2 buttons, and my onClick event is targeted to the add and remove methods, but for some reason, nothing happens either way. I'm only trying to output them right now, without even bothering with a div tag yet.

Here's what I have:



And my buttons call those methods.

Any ideas?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you're calling a function called "numbers" and passing it "x" as a parameter--do you have a function called "numbers"?

You're also setting your global "numbers" variable, initially defined as an array, to the result of calling "numbers(x)"--is this what you intend to do?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not use document.write after the page loads. You need to use DOM methods createElement and appendChild or innerHTML.

Eric
 
Heather Rose
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you are saying David, I am trying to have an array without defining a size (hence 'x').


Eric, can you give me an example of how I should go about displaying the numbers when I am through with my logic? Thanks.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.tizag.com/javascriptT/javascript-innerHTML.php
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Heather Rose wrote:I see what you are saying David, I am trying to have an array without defining a size (hence 'x').


I'm not really sure you do. If you define "numbers" as an Array it isn't going to let you run it as a function. When you write numbers(x) it's going to attempt to execute your array as a function, and it isn't one--it's an array. Firebug console:If you're trying to add a number to the numbers array, in other words the length of the array will increase by one every time you add a number, then you need to do something similar to:Or, alternatively:The second issue is the following:This *overwrites* your array--now not only do you not have a function, you don't have an array anymore.

(Or at least you wouldn't if you weren't getting a JavaScript exception when you tried to execute an array.)
 
Heather Rose
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, so I was playing with it a little more, and I got the numbers to work, but now it's a style sheet issue. Should be pretty simple, but I'm having a hard time figuring it out.

Now, I'm trying to make the numbers go ACROSS, not down. Now on the edges, I'm trying to make rounded, so I'm using an image background (basically just corners) for that. BUT, I want the background of that div to be the same color as the image. Is there a way to stretch the image so that I can do that?

Here's what I did for making the numbers work correctly:




 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A div is a block element.
A span is an inline element.

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic