Forum Moderators: open
I am having a difficult time to get the inline text effect from scriptalicious to work when the script is returned in an ajax response. I want to add that I am not a programmer by trade or education, but like to play around, so please forgive my hideous code.
Here is what is going on server side in the php file (pertinent info):
$returnValue .="</><br /><form id=\"poForm\" name =\"poForm\"><p id =\"invoice\" name =\"invoice\"><b>Invoice#(for multiple invoices separate with commas) ".$invoiceNums."</p>";
$returnValue .="<script type=\"text/javascript\">
inline('invoice', 'inline_editor.php');
</script></form>";
The $returnValue variable is echo'd out and the document goes through some parsing for proper div/s to update(there is obviously more to it then what I have shown)
I have this function on the main page to make sure the scriptalicious function loads ( Ithought that may have been my problem). It works with a test inline that is loaded immediately (not via ajax)
function inline(elementID, url, options){
new Ajax.InPlaceEditor(elementID, url);
}
ultimately what I get is the following script in the page:
<script type="text/javascript">
1
2 inline('invoice', 'inline_editor.php');
3
</script>
But no inline editing, although in the div below it the original still works just fine.
Looking through the forum I think somehow eval() may help solve this issue, but I can't figure out how to get it to work.
Any help would be very greatly appreciated.
$returnValue .="</><br /><form id=\"poForm\" name =\"poForm\"><p id =\"invoice\" name =\"invoice\"><b>Invoice#(for multiple invoices separate with commas) ".$invoiceNums."</p>";
$returnValue .="<script type=\"text/javascript\">".
inline('invoice', 'inline_editor.php')."
</script></form>";
$returnValue .="<script type=\"text/javascript\">
inline('invoice', 'inline_editor.php');
</script></form>";
could be rewritten to be
$returnValue .="<script type=\"text/javascript\">inline('invoice', 'inline_editor.php');</script></form>";
so you can see it better, the white space shouldn't count in php (I had it written that way because I was changing it so much it made it easier for me to know what I had changed). The interior semicolon is for the end of the javascript statement.
Again thanks for the try. Everything I read seems to lead me back to haw a function needs to be presented to prototype to be evaluated (I also tried eval()). Can eval() be used on a string that is intermixed with code or does the string have to be entirely code? Anyhow thanks again for the attempt.
function AJAXCallBack(){
//ajax code etc.
var form=document.getElementById('poForm');
form.innerHTML=form.innerHTML;
}
eval will only work if the returned stuff is all JS. I supose you could try picking out the code with RegEx but the above works usualy.
For now I am going to skip the scriptalicious effect and use a simpler solution. I may try your regex suggestion one day when I am bored though. Thanks again.