Link to home
Start Free TrialLog in
Avatar of dprasad
dprasad

asked on

Calling php from javascript link

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?
Avatar of Batalf
Batalf
Flag of United States of America image

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>
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>';
ASKER CERTIFIED SOLUTION
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rangi500
rangi500

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
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