[thelist] [Q] php and javascript

Jeff jeff at members.evolt.org
Sat May 13 07:36:44 2000


eduardo,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Eduardo Domínguez Martínez <edomingu@infosel.com.mx>
:
: Maybe this a bit off topic, but i am modifying
: Phorum (a php discussion programa ) so a
: new post pops up in a new window and also
: putting some javascript buttons i found on the
: net that ease html editing.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

yes, i can see the need for this, but it's really quite cumbersome isn't it?

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Then I found DhtmlEdit control, which lets you
: edit html in realtime (like ctrl-b gets you bold
: characters, and you can see them). This only
: runs on windows, so if the client is not windows
: i show a normal textarea.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

be careful with this blanket statement.  the dhtml edit control actually
only works in ie4+ on the pc.  it does not work in *any* other browsers.
since you're using php, just send the html, javascript, and stylesheets for
the dhtml edit control to the browser if it's windows ie4+ and send a
regular textarea to everyone else.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: The thing is, I havent been able to make this control
: work. Since it is an <object> i cannot process its
: contents with php. Someone suggested me to copy
: its contents to a hidden field of a form when the "post
: message" button was clicked; problem is, i dont know
: javascript and i dont know how to achieve this.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this is correct.  when submitting a form, only the contents of the form
elements get sent to the action page.  so, when the user attempts to submit
the form, grab the contents of the dhtml edit control and stuff them into a
form element.  assuming you're dhtml edit control is called dhtmledit, this
is what it might look like:

function get_html()
{
    return dhtmledit.document.body.innerHTML;
}

then, in your form tag you'll need to add an onSubmit event handler that
will call this get_html() function and put the contents into a specified
form field.  let's assume that you're using a textarea like this:

<textarea name="body" style="display : none"></textarea>

notice that it's set to "display: none".  that means that while the form
element will not be visible on the page, it will be visible to the page
that's called in the form action.  so, we want to set this textarea to the
contents of the dhtml edit control.  this is what your onSubmit event
handler in your form tag will look like:

onSubmit="document.all['body'].value = get_html()"

now, if you're giving your users the ability to edit the source code within
the dhtml edit control, then you'll need a slightly modified version of the
get_html() function that will grab the correct contents to send to your form
element.  assuming that you're keeping track of the mode the user is in with
a variable named bMode, then this is what the function would look like:

function get_html()
{
  if(bMode)
    return dhtmledit.document.body.innerHTML;
  else
    return dhtmledit.document.body.innerText;
}

fwiw, we're doing a test run on this dhtml edit control in the admin section
of evolt.org right now.  when i have everything working properly, then we'll
be offering it on the front end for people that are submitting articles.
keep your eyes open for it.

holler if you've got more questions,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff@members.evolt.org