mytvstation2010
mytvstation2010

Reputation: 1

Send information from javascript to php file

I have this function onEdit() and now I want to send the value of variable id to a php file (let's call it test.php) so that using that value I can auto fill the popup called modtemplate which is located in test.php file.

Is there any way to accomplish this?

Any help on this will be greatly appreciated!

function onEdit() {
    var checkboxs = document.getElementsByTagName("input");

    var id='';
    for (var b=0; b<checkboxs.length; b++) {
        if( (checkboxs[b].type == "checkbox") && (checkboxs[b].checked) )  {
            id = checkboxs[b].value;
                    break;
            }
    }

    if(!id)
        alert("Please select a record to edit");
    else    
        document.getElementById('modtemplate').style.visibility = 'visible';

}

Upvotes: 0

Views: 579

Answers (2)

Ibu
Ibu

Reputation: 43850

You can either use ajax to send the record and then use the response. or you can pass the value in the url like so

if(id) {
     window.location.href = "test.php?id="+id;
}

and in the server side u can retrive this value using the $_GET variable

$id = $_GET['id'];

For ajax it is a good idea to use jquery as it takes all the hard work out of the way

Upvotes: 1

AJ.
AJ.

Reputation: 28204

You need some AJAX, sir.

Upvotes: 5

Related Questions