Calling php from javascript link

Posted on 2005-04-06
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?
Question by:dprasad
    LVL 32

    Expert Comment

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


    <script type="text/javascript">
    function showEdit(linkObj){
        var obj = document.getElementById('editContainer');
            linkObj.innerHTML = 'Hide edit';
            linkObj.innerHTML = 'Show edit';        
    <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>
    LVL 20

    Expert Comment

    if you need to get something from your server to do it, have the DIV load an iframe..
    linkObj.innerHTML = '<IFRAME src=""></IFRAME>';
    LVL 32

    Accepted Solution

    Forgot to put in <form> and </form> in my example:

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

    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

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

    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.
    LVL 2

    Expert Comment

    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:


       img = new Image(1,1);
       img.src = "";


    LVL 11

    Expert Comment

    You mean something like this:

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

    Here is the link to the source:

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now