...

View Full Version : Getting variable from editable DIV



Sicton
08-21-2004, 09:04 PM
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.



<!-- 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.

jamescover
08-21-2004, 11:01 PM
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

Sicton
08-21-2004, 11:23 PM
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?

Willy Duitt
08-21-2004, 11:31 PM
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

Sicton
08-21-2004, 11:34 PM
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.

Willy Duitt
08-21-2004, 11:50 PM
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

Sicton
08-21-2004, 11:52 PM
Ah yes, that completely slipped my mind.

Problem solved, thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum