envexlabs Posted July 10, 2007 Share Posted July 10, 2007 Hey, I have an AJAX edit-in-place script that i'm using. Here is the code for editinplace.js: function init(){ makeEditable('desc'); makeEditable('pizza'); } 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 id="'+obj.id+'_save" type="button" value="SAVE" /> OR <input id="'+obj.id+'_cancel" type="button" value="CANCEL" /></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 saveChanges(obj){ var new_content = escape($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 = 'edit.php'; var pars = 'content='+new_content+'&edit=true'; var myAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure}); } I need to also pass a PHP variable, lets say $a, along with var url = 'edit.php' var pars = 'content='+new_content+'&edit=true'; but i dont know how to get the php variable from index.php -> editinplace.js -> edit.php Any help is greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/59268-using-php-variables-in-external-javascript-pages/ Share on other sites More sharing options...
shamilton Posted July 10, 2007 Share Posted July 10, 2007 Take the PHP variable and pass it in the URL. So with $ExamplePHPVaraible var url = 'edit.php?var=<?=$ExamplePHPVaraible?>' var pars = 'content='+new_content+'&edit=true'; Then somewhere get the variable: $hereItIs = (isset($_GET["var"])) ? $_GET["var"] : NULL; Hope that helps... Link to comment https://forums.phpfreaks.com/topic/59268-using-php-variables-in-external-javascript-pages/#findComment-294600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.