tags:

views:

306

answers:

3

Hello again and thanks for your effort! Since my previous question wasn't successful I thought I'd give it another approach.So the basic idea is to update my calendar event on mysql:

$eventQuery = mysql_query("SELECT id, body FROM tblCalEvent WHERE id= '$eid'", $conn);

which sits separately on a PHP file and works fine by returning ID and Body. Now, I need the body to be displayed in the textarea of this form (which sits on the main page with all javascript functions):

 <div style="display: none; margin-top: 10px;" id="editEvent">   
  <br>
                    <textarea id="evtBody" cols="20" rows="5" wrap="hard"></textarea>
  <br>
  <input type="button" value="save changes" onClick="updateEvent(($F('eid'),$F('evtDay'));">
        <input type="button" value="Cancel" onClick="Element.hide('editEvent');">

when I call this function:

function editEvent(eid, body) {

 if(Element.visible('editEvent')) {
  // do nothing, its already visble.
 } else {
  setTimeout("Element.show('editEvent')", 300);
 }
}

The form then calls the function below by passing the previous eid and edited body:

function updateEvent(eid, body) {

 new Ajax.Updater('editEvent','rpc.php', {method: 'post', postBody: 'action=updateEvent&&eid='+eid+'&body='+body+'', onSuccess: Element.hide('editEvent')});

 if(Element.visible('editEvent')) {
 Element.hide('editEvent');
 } else {
  setTimeout("Element.show('editEvent')", 300);
 }
}

I appreciate your suggestions! Below is what I tried unsuccessfully !

Hi everyone and thanks in advance for you help! This is really driving me nuts! What I'm trying to do is edit an event on my calendar by editing the text echoed in this form on my PHP file :

echo '<div style="background-color: white; margin-bottom: 4px; padding: 1px;" id="event_'.$e_id.'">
<textarea id="evtBody" cols="20" rows="5" wrap="hard"> '. nl2br($e_body) .'/textarea>
<input name="save" id = "save" type="button" value="Save" style="height:1.8em;width:3.5em;" onClick="updateEvent(('.$e_id.'), $F(\'evtBody\'))"/>

Everything works fine besides the last part $F(\'evtBody\') where the function returns an empty string which is not allowed in my database.

Here's my current function:

function updateEvent(eid, body) {

 alert(eid);// returns the Event ID correctly
 alert(body);// returns an empty string instead of text in the text area

 new Ajax.Updater('editEvent','rpc.php', {method: 'post', postBody: 'action=updateEvent&&eid='+eid+'&body='+body+'', onSuccess: Element.hide('editEvent')});

 if(Element.visible('editEvent')) {
 Element.hide('editEvent');
 } else {
  setTimeout("Element.show('editEvent')", 300);
 }
}
A: 

If I read the code correctly (it´s a bit of a mess...), you are using single quotes so $F will never be executed / parsed, it will just show $F in your html source code.

jeroen
I think $F is supposed to be in the javascript -- part of some javascript library (not jQuery)
Matt Bridges
Ah, in that case it's pretty hard to say why it returns an empty string, as the function is not given...
jeroen
$F is part of Prototype.js and I have no idea why I cannot make it work (I do understand it's human(me) error :), I'll try to get around this problem by using JQueryThanks for your help
+1  A: 

You're not using the $F() function correctly. See this Prototype page. You are supposed to pass an element to $F() but you are passing an ID instead. So, instead of this:

$F('evtBody')

You should be using this:

$F($('evtBody'))
Sander Marechal
I tried and I must be doing something awfully wrong, but I gave up on this and I'm going to try JQuery to get around this
A: 

Replace the updateEvent() function with this code:

function updateEvent(eid, body) {

    new Ajax.Updater('editEvent','rpc.php', {
  method: 'post',
  parameters: {
   action: 'updateEvent',
   eid: eid,
   body: body
  },
  onSuccess: Element.hide('editEvent')
 });

    if(Element.visible('editEvent')) {
    Element.hide('editEvent');
    } else {
            setTimeout("Element.show('editEvent')", 300);
    }
}

Tell me if it works

Pedro Cunha
Also, you should check your HTML, because I saw /textarea> but it should be </textarea>
Pedro Cunha
sorry Pedro, I took a little break from this part of the code but the answer is no, it didn't work and that is probably on the rpc.php i have problem with the $F() function which I'm going to go around by using JQuery.thanks for all your help