
-----------------------------------
samara
Thu Jun 04, 2009 1:04 pm

Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Approach 1:










var a;

function addItem() {
 a = document.getElementById("txtarea1").value;
 document.write('document.write(a);'); ----------------------------ERROR 
}




Comment 
document.write(a);





The code at the place error is not showing up like a javascript, and it is not executing!!
Can anyone help me, any suggestions please!!

-----------------------------------
octopi
Thu Jun 04, 2009 1:09 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Perhaps if you can better explain your end target/goal we can help you out.

-----------------------------------
samara
Thu Jun 04, 2009 1:16 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Approach 2:

Comments.Php Follows:




 

 
var a,b,d;
var count = 0;
function addcomment() {
a = document.getElementById("Comment").value;
if (count == 0) {
d = a; // d is the original value of the textarea before an additions
count ++;
}
'';
document.getElementById("comment").value = "";
self.location="Action.php?action=1";
}




Action.Php Follows:




        
        
            Comments
            document.write(a);          
        
        
       
        




When executing Comments.php and clicking on Add button, its getting transfered to Action.php but the code echo_header_detail is not getting executed.

Can anyone help me!! If it gets executed i also want to pass the value a from comments.php to action.php

Any help r suggestions please!!

-----------------------------------
samara
Thu Jun 04, 2009 1:24 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Octopi, Thanks for the quick turn over sir!!

I have to implement a comments section under a webpage which displays a report!!

1.) User should be able to add comments.

2.) Unfortunately we donot have any database!!

So when ever user adds comment and click add, the value in the textarea or textfield wherever he enters should be stored on the page as HTML content and an update and delete button should be generated beside the comment!!

My boss says, since there is no database, and users are less, whenever someone adds comments, the whole page should refresh r whatever you have to edit the html content  of the whole page.

so i wan to carete a textfiled and button, when user enters and clicks button, function should be called and it should get value from the textfield and display it somewhere on the same page!!

i am thinking of displaying it as a table Like:
-----------
[Text Field]  [add Button]
------------
when add is clicked, the page changes to
-----------
[Text Field] [add Button]

[Table Header]
[comment in row] [update button] [delete button]
-----------

-----------------------------------
octopi
Thu Jun 04, 2009 1:30 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Alright, From what I understand your best option would be to use PHP to read/write files. You shouldn't need any javascript for this.

Look into the methods:
http://ca3.php.net/manual/en/function.file-get-contents.php
http://ca3.php.net/manual/en/function.file-put-contents.php


When a user is posting a comment, write to a file.

When a user is requesting to view comments then just load the file, and display it.

-----------------------------------
samara
Thu Jun 04, 2009 1:47 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
Oh My God!!

this is the best reply i saw from so many posts!!

today is my second day in PHP, the links you gave, i was not able to understand how to implement it!!

can you please write  a piece of code for my situation, assuming any text field or button.

-----------------------------------
octopi
Thu Jun 04, 2009 1:53 pm

Re: Calling a PHP function from Javascript, Writing HTML in Javascript
-----------------------------------
[code]
