开发者

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

}


You need some AJAX, sir.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜