Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting variable from editable DIV

    Right, this has had me stumped for ages so I just had to ask on these forums. I'm trying to parse a variable from an editable DIV into php so it can process the variable as opposed to using just a textarea. The code I've got so far which doesn't work is as below.

    Code:
    <!-- Simple example of the PHP usage -->
    <?php
    
    if($_POST['postvar'] == '1'){
    
    echo $_POST['divEditable'];
    
    }
    
    ?>
    <script language="javascript"> 
    function getDiv() { 
    document.myForm.hiddenField.value = document.getElementById('divEditable').innerHTML;  
    return true;  
    } 
    </script>
    
    <form action="" method="post">
    <div id="divEditable" contenteditable="true" style="background: #F2F2F2"></div>
    <input type="hidden" name="postvar" value="1">
    <input type="submit" name="submit" value="Submit" onClick="getDiv();">
    </form>
    Any help would be grately appreciated. Sorry if this should be in the PHP section, it's just it seems to me it's in need more of javascript expertise.

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right, this has had me stumped for ages so I just had to ask on these forums. I'm trying to parse a variable from an editable DIV into php so it can process the variable as opposed to using just a textarea. The code I've got so far which doesn't work is as below.
    You didn't really explain what you are trying to do, but your code doesn't work because you can't parse anything in PHP, after the markup has already been sent to the client.

    Give a detailed explanation of what you are trying to do, and someone may be able to help you solve your problem.


    -james
    Last edited by jamescover; 08-21-2004 at 11:03 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right, ok, sorry that you didn't quite understand what I meant.

    I have an editable DIV which I am using as an alternative to a textarea. This DIV is to have the contents of a text file included into it which can then be edited and processed by php to be saved. While this is done with a text area it is just a simple case of naming the form element and the contents of the text area can be used as a variable when the form is processed, in order for the edited content to be saved. However, when the contents are in a DIV to be edited, I do not know how to get the contents of that DIV and use it in the same way as a text area can be used in order to be processed.

    Does that make it any clearer?

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why make it harder on your self than necassary....
    Do you realize that a textarea can be styled to look like a division without boders or margins....

    .....Willy

  • #5
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I do know that but it's nothing to do with aesthetics in this instance. I need to use a DIV since textarea has proven problematic when the text document loaded into the textarea contains the <textarea> tag it causes it to display incorrectly as it interupts the form.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are trying to display the tags which I assume from what little information you have provided, simply convert all < > to their respected ascii equivelents so that they are rendered as text not parsed as html....

    .....Willy

  • #7
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah yes, that completely slipped my mind.

    Problem solved, thanks.


  •  

    Posting Permissions

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