1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do I make <div> editable...

Discussion in 'JavaScript' started by LimeBlast, Mar 25, 2008.

  1. #1
    Can I (with Javascript) make <div></div> editable with out needing a textbox. Only by clicking in the div and write text.

    Any ideas?:cool:
     
    LimeBlast, Mar 25, 2008 IP
  2. So1

    So1 Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <div onClick="this.contentEditable='true';">lorem ipsum dolor lorem ipsum dolorlorem ipsum dolor</div>
     
    So1, Mar 25, 2008 IP
  3. elizas

    elizas Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Commonly we use textbox & textarea to write text by keyboard.But there is another control which can be used for the same pupose. Its DIV.

    Generally Div is used as container of other control or to show readonly text by setting the following property of div:

    contentEditable = "true"
     
    elizas, May 5, 2010 IP
  4. skier88

    skier88 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The method has been posted. However, I would recommend staying away from this unless you are sure it is suitable for your purpose, as it is not as compatible as a textarea, there are no visual cues (so you would want to change styles via js as well), it requires javascript both to function and to submit (if you want to use what the user puts in the div), and it is easy to forget and put something you don't want them to edit inside the box.
     
    skier88, May 8, 2010 IP
  5. bprashanth.gi

    bprashanth.gi Active Member

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    93
    #5
    If you want an 'invisible' textarea/textbox, you can try setting the color related properties of the control to colors of the background on which they are placed.

    As skier88 pointed out, this may cause some problems (the code in my IE7 shows security warning which some users may not like) which you may regret later.
     
    bprashanth.gi, May 10, 2010 IP