Skip to content Skip to sidebar Skip to footer

Unable To Run Php Function To Update Db Value Using Document.write

In the code given below, I am using a repeater field to store the image links and ranks. In the front-end I am trying to implement something like this: when I select a different ra

Solution 1:

The comments say it all but I'll sum up. PHP as a server side language is evaluated before the code reaches your browser - on the other hand javascript as a client side language executes only after your browser has received the information from the server. To use javascript to call a php function you'll need to make an asynchronous request (if you don't want your page to reload at least). An example Ajax request (from http://www.w3schools.com/php/php_ajax_php.asp):

var xmlhttp = newXMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET", "gethint.php?q=" + str, true);
    xmlhttp.send();

Also in your php code you'll need a function that returns the needed information called like if($_GET['q'] ==...){//your function here}

Post a Comment for "Unable To Run Php Function To Update Db Value Using Document.write"