?
Solved

Calling php from javascript link

Posted on 2005-04-06
5
Medium Priority
?
244 Views
Last Modified: 2008-02-01
I need to display a php form yo make an update, but would like to do it underneath the current table within the same page like:


<a href = "#" onclick = "showedit();"return false;">Edit</a></div></td></div></td>

It should show a form with a submit button, any ideas?
0
Comment
Question by:dprasad
5 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13721307
If the data you want to edit is available on the page, you could just show/hide a div object.

Example:

<script type="text/javascript">
function showEdit(linkObj){
    var obj = document.getElementById('editContainer');
    if(obj.style.display=='none'){
        obj.style.display='block';
        linkObj.innerHTML = 'Hide edit';
    }else{
        obj.style.display='none';
        linkObj.innerHTML = 'Show edit';        
       
    }
   
}
</script>
<table>
<tr><td>
<a href = "#" onclick = "showEdit(this);"return false;">Show edit</a><div id="editContainer" style="display:none">
    <table border="0">
        <tr><td><input type="submit" name="update"></td></tr>
        <tr><td>Name:<td><input type="text" name="firstName" value="My name"></td></tr>
        <tr><td>Address:<td><input type="text" name="address" value="My Address"></td></tr>
    </table>
</div></td></div></td></tr>
</table>
0
 
LVL 20

Expert Comment

by:virmaior
ID: 13721336
if you need to get something from your server to do it, have the DIV load an iframe..
e.g.
linkObj.innerHTML = '<IFRAME src="www.microsoft.com/myform.php"></IFRAME>';
0
 
LVL 32

Accepted Solution

by:
Batalf earned 2000 total points
ID: 13721395
Forgot to put in <form> and </form> in my example:

<tr><td>
<a href = "#" onclick = "showEdit(this);"return false;">Show edit</a><div id="editContainer" style="display:none">
   
    <table border="0">
        <tr><tr><td><form action="whatever.php" method="post">Name:<td><input type="text" name="firstName" value="My name"></td></tr>
        <tr><tr><td>Address:<td><input type="text" name="address" value="My Address"></td></tr>
    </table>
    </form>
</div></td></div></td></tr>

The iframe solution mentioned by virmajor is also a very good thought. But maybe you only need to put the iframe within the div originally instead of using innerHTML!?

Something like

<tr><td>
<a href = "#" onclick = "showEdit(this);"return false;">Show edit</a><div id="editContainer" style="display:none">
<iframe src="edit.php?id=whatever" width="500" height="200"></iframe>
</div></td></div></td></tr>

and then have your form inside edit.php. You could also change the source of that iframe if you need functionality where you could specify which item to edit.
0
 
LVL 2

Expert Comment

by:rangi500
ID: 13727334
If you just want to make a one-way call to a php script, without getting anything back from the script, you can do this by loading a javascript "image". For example, if you want to pass the value "my_value" to the script "my_script.php" then you can do this:

<script>

   img = new Image(1,1);
   img.src = "http://www.example.com/my_script.php?my_parameter1=my_value";

</script>

Rangi
0
 
LVL 11

Expert Comment

by:neester
ID: 13741910
You mean something like this:

http://www.modernmethod.com/sajax/sajax-0.10/php/example_wall.php

The page never refreshes.
It uses javascript to run a CHAT window.
:)

Here is the link to the source:

http://www.modernmethod.com/sajax/sajax-0.10/php/example_wall.php.txt
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question