Uran
Uran

Reputation:

Retrieve text from TextArea!

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);
    }
}

Upvotes: 1

Views: 677

Answers (3)

Pedro Cunha
Pedro Cunha

Reputation: 164

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

Upvotes: 0

Sander Marechal
Sander Marechal

Reputation: 23216

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'))

Upvotes: 1

jeroen
jeroen

Reputation: 91734

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.

Upvotes: 0

Related Questions