Creating elements on the page with Javascript

Discussion in 'JavaScript' started by x2i, Jun 8, 2006.

  1. #1
    Hi, im fairly new to Javascript but you could say Im a fast learner. I have been wondering if there is a way to do the following:

    I want to allow the user to create as many instances of elements as they wish. For example if they click a button then it clones it as a new object on the page. Kind of like creating elements at run-time.

    If this doesnt make sense then please ask and Ill describe it in more detail - any help is appreciated. Thankyou

    Dan :)
     
    x2i, Jun 8, 2006 IP
  2. Vallim

    Vallim Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi Peon,

    Do u mean that u need to create the control dynamically. ie when u click an html button u need other new instance of the html button to be created.
    Can u be more clear.

    Valli
     
    Vallim, Jun 14, 2006 IP
  3. DonkeyTeeth

    DonkeyTeeth Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It depends what you mean by 'elements'. It would be relatively easy to do with things like table rows/columns or text. Form controls can also be created/hidden on the fly.

    How easy any of this is would depend on how well you plan out your page design so that javascript can identify elements and create new instances of them. At the minimum, divs and page elements should have Id's defined so you can refer to them by those Ids in javascript.

    Do you have more specific examples of the kind of elements you want users to be able to clone?
     
    DonkeyTeeth, Jun 15, 2006 IP
  4. x2i

    x2i Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To be entirely honest any element would be handy - form, div and table elements.

    I dont know how to explain it in more detail but ill try below:

    here is a button (id = "but1") --> |BUTTON|
    when you click "but1" it clones an exact copy of this button onto the stage, and everytime you click this button it clones another of the same button but through an array (if that makes sense)

    Please ask if still unsure and ill code a demonstration thing for you. Dan
     
    x2i, Jun 19, 2006 IP