/    Sign up×
Community /Pin to ProfileBookmark

JavaScript – can`t pull content

i have a <p> attribute which on click is changed to AJAX-EDIT-IN-PLACE <textarea> FORM

here is this <p> tag

[CODE]
<p id=”desc”>”.$row[‘description’].”</p>
[/CODE]

everything forks fine:

but in my case $row[‘description’] is the Title of some information, and sure its Dinamycaly Genereted..

so when i edit This description using AJAX-edit-in-place form after this javascript starts working:

it grabs some information from <p> tag and sends it to update.php file

these are two strings:

  • 1. is [B]$ID[/B] which is just a text “desc”

  • 2. and [B]$conten[/B] which contains changed title
  • after these strings passed to php file… php must go to db and update specified row[title]

    but there no information which row to be updated
    so i wanted to change id = “desc” to id = “$cat_id” but in this case javascript false and no more edit-in-place is possible

    becaus in js there is CODE LIKE THIS:

    [CODE]
    function init(){
    makeEditable(‘desc’);
    }
    [/CODE]

    so i decided to add name attribute to <p> tag and did it this way

    [code=php]<p name=’$cat_id’ style=’font-family:BPG Glaho Arial V5; font-size:12px;’ id=”desc”>”.$row[‘description’].”</p>
    [/code]

    but now i can`t make js file to grab name=”content” to php file

    can someone help me? thank you:

    HERE IS JS FILE WHICH GRABS AND SENDS ALL DATA TO PHP FILE

    [CODE]
    <script type=”text/javascript”>
    Event.observe(window, ‘load’, init, false);

    function init(){
    makeEditable(‘desc’);

    }

    function makeEditable(id){
    Event.observe(id, ‘click’, function(){edit($(id))}, false);
    Event.observe(id, ‘mouseover’, function(){showAsEditable($(id))}, false);
    Event.observe(id, ‘mouseout’, function(){showAsEditable($(id), true)}, false);
    }

    function edit(obj){
    Element.hide(obj);

    var textarea = ‘<div id=”‘+obj.id+’_editor”><textarea id=”‘+obj.id+’_edit” name=”‘+obj.id+'” rows=”4″ cols=”60″>’+obj.innerHTML+'</textarea>’;
    var button = ‘<div><input style=”border:1px #fff solid; background-color:#F1F1F1; font-family:Tahoma; text-transform:uppercase; font-size:10px;” id=”‘+obj.id+’_save” type=”button” value=”save changes” />&nbsp;&nbsp;<input style=”border:1px #fff solid; background-color:#F1F1F1; font-family:Tahoma; text-transform:uppercase; font-size:10px;” id=”‘+obj.id+’_cancel” type=”button” value=”Forget Changes” /></div></div>’;

    new Insertion.After(obj, textarea+button);

    Event.observe(obj.id+’_save’, ‘click’, function(){saveChanges(obj)}, false);
    Event.observe(obj.id+’_cancel’, ‘click’, function(){cleanUp(obj)}, false);

    }

    function showAsEditable(obj, clear){
    if (!clear){
    Element.addClassName(obj, ‘editable’);
    }else{
    Element.removeClassName(obj, ‘editable’);
    }
    }

    function saveChanges(obj){

    var new_content = ($F(obj.id+’_edit’));

    obj.innerHTML = “Saving…”;
    cleanUp(obj, true);

    var success = function(t){editComplete(t, obj);}
    var failure = function(t){editFailed(t, obj);}

    var url = ‘./inc/UpdateGalleryTitle.php’;
    var pars = ‘id=’+obj.id+’&content=’+new_content+’&name=’+obj.name;
    var myAjax = new Ajax.Request(url, {method:’post’, postBody:pars, onSuccess:success, onFailure:failure});

    }

    function cleanUp(obj, keepEditable){
    Element.remove(obj.id+’_editor’);
    Element.show(obj);
    if (!keepEditable) showAsEditable(obj, true);
    }

    function editComplete(t, obj){
    obj.innerHTML = t.responseText;
    showAsEditable(obj, true);
    }

    function editFailed(t, obj){
    obj.innerHTML = ‘Sorry, the update failed.’;
    cleanUp(obj);
    }
    </script>

    [/CODE]

    THANK YOU !

    to post a comment
    JavaScript

    0Be the first to comment 😎

    ×

    Success!

    Help @LogicOpinion spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...