Results 1 to 4 of 4

Thread: Change textarea to editable...

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default Change textarea to editable...

    I have a confirmation page and on it, there's a textarea that's readonly. I want to have an edit button under it, however, that if clicked, the textarea isn't readonly anymore.

    The textarea's name is created dynamically, so I can't call the textarea that way. However, I could give the form itself a name. Here's the code:

    HTML Code:
    <form method="post" action="write.php">
    <textarea name="dynamic_name" readonly>TEXTAREA CONTENT</textarea><br />
    <input type="button" value="Edit" />
    <input type="submit" value="Submit" />
    </form>
    Is there some sort of onclick event I can add to the Edit button?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, I wrote something I think may work:

    JavaScript:
    Code:
    var textareas = 
    	document.getElementsByTagName("textarea"); 
    
    for (var i=0, l=textareas.length; i < l; i++){ 
    	textareas[i].readonly = false; }
    		
    function addEvent(el,ev,fn){ 
    	if(el.addEventListener) 
    		el.addEventListener(ev,fn,false) 
    	else el.attachEvent('on'+ev, fn) }
    	
    addEvent(document.getElementById("editButton"), "click", enableTextareas);
    HTML:
    HTML Code:
    <form method="post" action="write.php">
    <textarea name="dynamic_name" readonly>TEXTAREA CONTENT</textarea><br />
    <input type="button" value="Edit" id="editButton" />
    <input type="submit" value="Submit" />
    </form>
    It isn't working, though. What's wrong? I know it's because the function enableTextareas doesn't exist, but I'm not entirely sure what to put in that function...
    Last edited by alexjewell; 07-02-2007 at 01:49 PM.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Hey, I fixed the problem. Finished code:

    Code:
    function changeTextarea(bool,idis) {
    
    	if(bool) { document.getElementById(idis).readOnly = false;}
    
    	else { document.getElementById(idis).readOnly = true;}}
    html:
    HTML Code:
    <form method="post" action="something.php">
    	<textarea name="something" id="something" readonly>TEST</textarea><br />
    	<input type="button" value="Edit" onclick="changeTextarea(this.onclick,'something')" />
    	<input type="submit" value="Submit" />
    </form>
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you swap those two arguments around, the second one can be optional. Mind the pseudo-XHTML.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •